0
0
Dockerdevops~10 mins

GitLab CI with Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - GitLab CI with Docker
GitLab CI Pipeline Triggered
GitLab Runner Starts Job
Runner Uses Docker Executor
Docker Container Created
CI Script Runs Inside Container
Job Completes
Container Stops and Removes
Pipeline Reports Status
This flow shows how GitLab CI triggers a job, runs it inside a Docker container, and reports the result.
Execution Sample
Docker
image: docker:latest

services:
  - docker:dind

script:
  - docker info
  - echo "Hello from Docker in GitLab CI"
This GitLab CI config runs a job using Docker image and Docker-in-Docker service, then prints Docker info and a message.
Process Table
StepActionDetailsResult
1Pipeline triggeredGitLab detects push or merge requestPipeline starts
2Runner picks jobGitLab Runner assigned to jobRunner starts job
3Docker container createdRunner uses docker:latest imageContainer ready
4Docker-in-Docker service startsdocker:dind service runs alongsideDocker daemon available
5Run 'docker info'Inside container, command executedDisplays Docker daemon info
6Run echo commandPrint message inside containerOutputs: Hello from Docker in GitLab CI
7Job completesAll script commands doneJob success
8Container stopsRunner cleans up containerNo leftover containers
9Pipeline reportsGitLab shows job statusSuccess shown
10ExitNo more stepsPipeline finished
💡 Pipeline finishes after all script commands run and container is cleaned up
Status Tracker
VariableStartAfter Step 3After Step 5After Step 7Final
Pipeline StatusNot startedRunningRunningSuccessSuccess
Docker ContainerNoneCreatedRunningStoppedRemoved
Docker DaemonNot availableStartingAvailableAvailableStopped
Key Moments - 3 Insights
Why do we need the docker:dind service in GitLab CI?
The docker:dind service runs a Docker daemon inside the CI environment, allowing Docker commands like 'docker info' to work inside the container, as shown in execution_table step 4 and 5.
What happens to the Docker container after the job finishes?
After the job completes (step 7), the container stops and is removed by the runner to keep the environment clean, as seen in steps 8 and 9.
How does GitLab CI know the job succeeded?
GitLab CI checks the exit status of the script commands inside the container. If all commands succeed, the pipeline status changes to success (step 7 and 9).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of the Docker container after step 5?
ACreated but not running
BStopped and removed
CRunning inside the job
DNot created yet
💡 Hint
Check the 'Docker Container' variable in variable_tracker after Step 5
At which step does the GitLab Runner clean up the Docker container?
AStep 8
BStep 7
CStep 6
DStep 9
💡 Hint
Look at execution_table rows describing container stop and removal
If the docker:dind service was not included, what would happen at step 5?
Adocker info would show daemon info as usual
Bdocker info would fail because no Docker daemon is running
CThe job would skip docker info command
DThe container would not start
💡 Hint
Refer to key_moments about why docker:dind service is needed
Concept Snapshot
GitLab CI with Docker:
- Use 'image: docker:latest' to run Docker commands
- Add 'services: - docker:dind' for Docker daemon
- Runner creates container, runs scripts inside
- Docker container stops and cleans after job
- Pipeline status reflects script success or failure
Full Transcript
This visual execution shows how GitLab CI uses Docker to run jobs. When a pipeline triggers, GitLab Runner starts a job using the docker:latest image. It also runs the docker:dind service to provide a Docker daemon inside the container. The job runs commands like 'docker info' and prints messages inside the container. After the job finishes, the container stops and is removed. GitLab reports the job status as success if all commands run without errors. This process ensures isolated, repeatable builds using Docker containers in GitLab CI.