Bird
0
0

You have this GitLab CI job configuration:

medium📝 Troubleshoot Q14 of 15
Docker - in CI/CD
You have this GitLab CI job configuration:
build:
  image: docker:latest
  script:
    - docker build -t myapp .
  services:
    - docker:dind
The job fails with error: Cannot connect to the Docker daemon. What is the most likely fix?
AAdd <code>variables: DOCKER_HOST: tcp://docker:2375</code> to the job
BChange image to <code>docker:dind</code>
CRemove the services section
DAdd <code>docker login</code> before build
Step-by-Step Solution
Solution:
  1. 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.
  2. 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.
  3. Final Answer:

    Add variables: DOCKER_HOST: tcp://docker:2375 to the job -> Option A
  4. Quick Check:

    Set DOCKER_HOST to connect client to dind daemon [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes