GitLab CI job cannot reach the docker service: 'lookup docker ... no such host'
error during connect: Post "https://docker:2376/v1.24/auth": dial tcp: lookup docker ... no such hostShort answer
The job's Docker client tries to reach the dind service by the hostname docker, and DNS finds nothing. Either the service never started (usually a runner without privileged mode), or its image name changed the hostname the runner derives. Read the dind service log in the job output first, then fix privileged mode or add the alias.
Fix it fast
1Find out which cause you have
Run docker info as the first command of the job and read the job log above the failure: the dind service writes its own start-up errors there.
before_script: - docker info2Match what you see, then jump to its fix
- 1
The service log shows 'mount: permission denied (are you root?)' and the error names docker:2376The dind service did not start because the runner is not privilegedFix - 2
The service is declared as registry.example.com/library/docker:24.0.5-dind and starts fine, but docker is not foundThe service image name includes a registry hostFix - 3
Cannot connect to the Docker daemon at tcp://docker:2375, or builds fail with 'cgroups: cgroup mountpoint does not exist'An old dind image, or a TLS setting mismatch with the clientFix - 4
Cannot connect to the Docker daemon at unix:///var/run/docker.sockDocker variables are missing in a job that relied on legacy linksFix
- 1
What does the error look like?
error during connect: Post "https://docker:2376/v1.24/auth": dial tcp: lookup docker ... no such hostdocker: error during connect: ... lookup docker ... no such hostCannot connect to the Docker daemon at tcp://docker:2375
Cause 1 of 4
The dind service did not start because the runner is not privileged
1Check
Docker-in-Docker needs a runner with privileged mode. Look at the runner's config.toml, and at the tags your job selects.
sudo grep -n -E "privileged|volumes" /etc/gitlab-runner/config.toml2Fix
Set privileged = true for the runner (and keep the /certs/client volume), and make sure the job uses tags that select that runner.
[runners.docker]
privileged = true
volumes = ["/certs/client", "/cache"]3Verify
Restart the runner, rerun the job, and check that docker info prints server details.
sudo gitlab-runner restart
# in the job
docker infoConfirmed by docs.gitlab.com
Cause 2 of 4
The service image name includes a registry host
1Check
The hostname the job uses for the service comes from the image name. A registry hostname in the name changes it, but the Docker client expects docker.
grep -n -A3 "services:" .gitlab-ci.yml2Fix
Give the service the alias docker.
services:
- name: registry.example.com/library/docker:24.0.5-dind
alias: docker3Verify
Rerun the job: docker info reaches the daemon.
docker infoConfirmed by docs.gitlab.com
Cause 3 of 4
An old dind image, or a TLS setting mismatch with the client
1Check
Docker-in-Docker 19.03 and later starts with TLS on (port 2376), so a client pointed at tcp://docker:2375 cannot connect. A dind image older than 20.10 fails on hosts running Docker Engine 20.10 or newer.
grep -n -E "DOCKER_HOST|DOCKER_TLS_CERTDIR|dind" .gitlab-ci.yml2Fix
Use a current dind image and the documented TLS setup: set DOCKER_TLS_CERTDIR to /certs. For the TLS-enabled Docker executor setup the docs do not set DOCKER_HOST, because Docker 19.03 and later set it automatically.
image: docker:24.0.5-cli
services:
- docker:24.0.5-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"3Verify
docker info in before_script prints the server version.
docker infoConfirmed by docs.gitlab.com
Cause 4 of 4
Docker variables are missing in a job that relied on legacy links
1Check
The job has no Docker connection variables. Old setups relied on DOCKER_PORT_2375_TCP from the deprecated --link flag, which stops working when FF_NETWORK_PER_BUILD is true.
grep -n -E "DOCKER_HOST|FF_NETWORK_PER_BUILD" .gitlab-ci.yml2Fix
Set DOCKER_HOST explicitly, with the TLS variables if TLS is on. For the Kubernetes setup the docs use tcp://docker:2376.
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"3Verify
Rerun the job and run docker info first.
docker infoConfirmed by docs.gitlab.com
How do I stop it coming back?
- Put docker info at the start of every dind job so a daemon problem fails there and not at docker login.
- Keep the dind image at the same major version as the docker client image.
- Use runner tags so jobs that need privileged mode only run on runners that allow it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix