GitLab CI is a tool built into GitLab that helps automate testing, building, and deploying your code using pipelines.
Click to reveal answer
beginner
Why use Docker in GitLab CI pipelines?
Docker lets you run your code in containers, which are like small, consistent environments. This makes sure your code runs the same way everywhere.
Click to reveal answer
beginner
What is a .gitlab-ci.yml file?
It is a file in your project that tells GitLab CI what steps to run, like building or testing your code, and how to run them.
Click to reveal answer
beginner
How do you specify a Docker image in GitLab CI?
You add 'image: ' at the top of your .gitlab-ci.yml file to tell GitLab which Docker image to use for running jobs.
Click to reveal answer
intermediate
What is the purpose of the 'services' keyword in GitLab CI with Docker?
The 'services' keyword lets you run extra Docker containers alongside your job, like a database, so your tests can use them.
Click to reveal answer
In GitLab CI, how do you tell the pipeline to use a specific Docker image?
ABy setting environment variables in GitLab UI
BBy running 'docker run' command in the terminal
CBy installing Docker manually on the runner
DBy adding 'image: <image-name>' in .gitlab-ci.yml
✗ Incorrect
You specify the Docker image directly in the .gitlab-ci.yml file using the 'image' keyword.
What does the 'services' keyword do in a GitLab CI pipeline?
AStarts the GitLab server
BDefines the main Docker image for the job
CRuns additional Docker containers alongside the job
DUploads artifacts after the job finishes
✗ Incorrect
'services' runs extra containers like databases that your job can connect to during execution.
Which file controls the steps and Docker images used in GitLab CI?
A.gitlab-ci.yml
BDockerfile
CREADME.md
Dconfig.yml
✗ Incorrect
The .gitlab-ci.yml file defines the pipeline jobs, steps, and Docker images.
Why is Docker useful in CI pipelines?
AIt creates consistent environments for running code
BIt speeds up internet connection
CIt replaces GitLab entirely
DIt stores code backups
✗ Incorrect
Docker containers ensure your code runs the same way on any machine by packaging dependencies.
What happens if you don't specify a Docker image in GitLab CI?
ADocker will not be installed
BGitLab uses a default image or the runner's environment
CThe pipeline will fail immediately
DThe job will run on your local machine
✗ Incorrect
GitLab uses a default image or the runner's environment if no image is specified.
Explain how to set up a simple GitLab CI pipeline that uses Docker to run tests.
Think about the file, image, jobs, and running commands.
You got /5 concepts.
Describe the role of Docker containers in GitLab CI pipelines and why they are helpful.
Focus on environment consistency and isolation.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using docker:dind service in a GitLab CI pipeline?
easy
A. To send notifications after the pipeline finishes
B. To deploy the application to production automatically
C. To run Docker commands inside the CI job container
D. To store build artifacts permanently
Solution
Step 1: Understand the role of docker:dind
The docker:dind (Docker-in-Docker) service allows Docker commands to run inside a container, which is essential for building and managing Docker images during CI jobs.
Step 2: Identify the purpose in GitLab CI context
In GitLab CI, using docker:dind lets the pipeline build, run, and push Docker images isolated from the host system.
Final Answer:
To run Docker commands inside the CI job container -> Option C
Quick Check:
docker:dind = run Docker commands in CI [OK]
Hint: Remember: dind means Docker runs inside Docker [OK]
Common Mistakes:
Confusing dind with deployment step
Thinking dind stores artifacts
Assuming dind sends notifications
2. Which of the following is the correct way to specify the Docker service in a GitLab CI job to enable Docker commands?
easy
A. services:
- docker:dind
B. services:
- docker:latest
C. services:
- docker:build
D. services:
- docker:run
Solution
Step 1: Recall the correct service name for Docker-in-Docker
The official Docker-in-Docker service image is docker:dind, which must be specified exactly to enable Docker commands in GitLab CI.
Step 2: Compare options to find exact match
Only services:
- docker:dind uses the correct service name docker:dind. Other options are invalid or do not exist as official images.
Final Answer:
services:
- docker:dind -> Option A
Quick Check:
Correct service name = docker:dind [OK]
Hint: Use exact service name 'docker:dind' for Docker commands [OK]
Common Mistakes:
Using 'docker:latest' instead of 'docker:dind'
Adding extra tags like 'build' or 'run'
Omitting the services section
3. Given this GitLab CI job snippet, what will be the output of the docker ps command inside the job?
B. Lists running containers inside the dind service (likely empty)
C. Lists containers on the host machine
D. Outputs the Docker version only
Solution
Step 1: Understand the environment of the job
The job uses docker:dind service, which runs a Docker daemon inside the CI environment. The docker ps command connects to this daemon.
Step 2: Predict the output of docker ps
Since the job just started and no containers were run inside the dind daemon, docker ps will list running containers inside the dind environment, which is likely empty.
Final Answer:
Lists running containers inside the dind service (likely empty) -> Option B
The job fails with error: Cannot connect to the Docker daemon. What is the most likely fix?
medium
A. Add variables:
DOCKER_HOST: tcp://docker:2375 to the job
B. Change image to docker:dind
C. Remove the services section
D. Add docker login before build
Solution
Step 1: Identify cause of Docker daemon connection error
The error means the Docker client inside the job cannot reach the Docker daemon running in the docker:dind service container.
Step 2: Fix connection by setting DOCKER_HOST variable
Setting DOCKER_HOST: tcp://docker:2375 tells the Docker client to connect to the dind service over TCP, enabling communication.
Final Answer:
Add variables:
DOCKER_HOST: tcp://docker:2375 to the job -> Option A
Quick Check:
Set DOCKER_HOST to connect client to dind daemon [OK]
Hint: Set DOCKER_HOST to tcp://docker:2375 to fix connection [OK]
Common Mistakes:
Changing image to docker:dind instead of using service
Removing services section disables Docker daemon
Adding docker login does not fix daemon connection
5. You want to build a Docker image and push it to GitLab Container Registry in a GitLab CI job. Which snippet correctly sets up the job with Docker-in-Docker and pushes the image?