GitLab CI "Cannot connect to the Docker daemon" (dind)
Your job ran a docker command but there is no daemon to talk to. In GitLab CI you must attach a Docker-in-Docker service and point the client at it.
What this error means
A docker build/docker push step fails immediately: "Cannot connect to the Docker daemon ... Is the docker daemon running?" The rest of the job is fine - only Docker has nowhere to connect.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?Common causes
No dind service attached
The Docker executor does not give jobs a daemon by default. Without a docker:dind service, there is no daemon for the client to reach.
DOCKER_HOST / TLS not configured
With dind over TLS, the client needs DOCKER_HOST, DOCKER_TLS_CERTDIR, and the cert path set. Missing or mismatched values leave the client pointed at a non-existent socket.
How to fix it
Attach docker:dind and set the host
build:
image: docker:27
services:
- docker:27-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "/certs/client"
DOCKER_TLS_VERIFY: "1"
script:
- docker build -t myimage .Or use the host socket deliberately
If your runner is configured to mount /var/run/docker.sock, you do not need dind - but this shares the host daemon and is a security trade-off.
How to prevent it
- Standardize a dind template (
services,DOCKER_HOST, TLS) andextendsit. - Pin matching
dockeranddocker:dindversions. - Avoid socket-binding on shared runners for security.