Prerequisites
- A GitLab Runner with Docker-in-Docker support enabled
- CI/CD variables set for
DOCKER_USERNAME,M_DB_PASSWORD, and any other secrets - A Docker Hub account configured to push images
CI/CD Pipeline Configuration
Add acontainerization stage to your existing .gitlab-ci.yml. The new docker_build job will build and list your Docker image:
Variable Definitions
Make sure sensitive values like
MONGO_PASSWORD are stored as masked CI/CD variables to avoid exposure in job logs.Sample Dockerfile
Place thisDockerfile at the root of your repository to containerize a Node.js application:
Pipeline Execution Flow
When you push tomain or open a feature merge request, GitLab:
- Launches the docker:24.0.5 image for the job.
- Starts the Docker-in-Docker service (
docker:24.0.5-dind). - Runs the
scriptsection to build and list the image:
