Cannot connect to the Docker daemon (docker.sock / dockerd)
The Docker client talked to a socket or TCP endpoint and nobody answered like a daemon. Either dockerd is stopped, the socket path is wrong, or you are pointing at the wrong host.
How it shows up
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
error during connect: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.45/containers/json": dial unix /var/run/docker.sock: connect: no such file or directory
Compose, buildx, and language SDKs surface the same underlying dial failure.
Client vs daemon
- The client is the
dockerbinary (or library) on your PATH. - The daemon is
dockerd(Linux) or Docker Desktop’s VM engine. - They meet at a socket (
/var/run/docker.sock) or a TCP/SSH context (DOCKER_HOST).
This error is “client could not speak to daemon”. It is not a failed docker build inside an already-connected session.
vs permission denied
| Message | Means |
|---|---|
| Cannot connect … Is the docker daemon running? | Socket missing, connection refused, or wrong host — daemon likely down / wrong endpoint |
| permission denied while trying to connect to docker.sock | Socket exists; your user is not in the docker group (or bad ACLs) |
| connection refused on DOCKER_HOST TCP | Nothing listening on that host:port |
Frequent causes
- dockerd / Docker Desktop not running — service stopped; Desktop quit; WSL distro not integrated.
- Socket path — rootless Docker uses
$XDG_RUNTIME_DIR/docker.sock; snap/podman emulation may differ. - Bad DOCKER_HOST / context — leftover
export DOCKER_HOST=tcp://…pointing at a dead machine;docker context usestuck on remote. - CI / container-in-container — job expects a sibling daemon or DinD service that was never started; sock not mounted.
- After crash / disk full — daemon failed to start (also check ENOSPC and docker system prune).
Diagnose
# What does the client think it should dial?
docker context ls
echo "DOCKER_HOST=$DOCKER_HOST"
ls -l /var/run/docker.sock 2>/dev/null || echo "no sock"
# Linux service
systemctl status docker --no-pager
journalctl -u docker -n 50 --no-pager
# Can anything accept the sock?
curl -s --unix-socket /var/run/docker.sock http://localhost/_ping && echo
# Desktop / WSL: start Docker Desktop, then
wsl -e docker version
Fix checklist
- Start the engine —
sudo systemctl start docker(andenableif you want it on boot), or launch Docker Desktop and wait until it says running. - Clear a bad host —
unset DOCKER_HOST;docker context use default. - Rootless — start the user service (
systemctl --user start docker) and export the rootless socket if documented for your install. - Permissions — if the sock exists and you get permission denied, fix group membership (docker.sock permission denied), not “daemon running” alone.
- CI — ensure the DinD service is healthy and
DOCKER_HOSTmatches (oftentcp://docker:2375or a mounted sock). - Space / corruption — if dockerd exits immediately, free disk and inspect logs before retrying pulls.
# After the daemon is up
docker version # Client + Server sections both populated
docker info | head
docker run --rm hello-world
Related
docker.sock permission denied · docker system prune / reclaim space · ENOSPC no space left · localhost refused to connect · Permission denied (publickey) · getaddrinfo ENOTFOUND
Questions
What does Cannot connect to the Docker daemon mean?
The Docker client could not reach dockerd at the configured socket or DOCKER_HOST. Usually the daemon is stopped or the endpoint is wrong.
Is the docker daemon running?
Check systemctl status docker, Docker Desktop status, or docker context. If /var/run/docker.sock is missing, the engine is not up (or uses another path).
How is this different from permission denied on docker.sock?
Permission denied means the socket exists but your user cannot access it. Cannot connect usually means nothing to connect to, or the wrong host.
What is DOCKER_HOST?
An environment variable telling the client where the daemon API is (unix socket or tcp/ssh URL). A stale value is a common cause of this error.
How do I fix it on Linux?
sudo systemctl start docker, unset bad DOCKER_HOST, use the default context, then docker version should show a Server section.
How do I fix it with Docker Desktop / WSL?
Start Docker Desktop, enable WSL integration for your distro, wait until it is idle/running, then retry docker version inside WSL.
Published .