Cannot connect to the Docker daemon — 5 Reasons and How to Diagnose Each
Symptom: every docker command gets rejected
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
One-line diagnosis: the docker CLI client is alive, but the dockerd daemon it talks to is not. The client reaches the daemon through a Unix socket (or TCP/SSH); if nothing answers there, this is the error. Note the difference from permission denied — that one means "the socket exists but you may not touch it"; this one means "the socket doesn't exist or nobody is behind it".
Five causes, ranked by frequency
1. The daemon isn't running (most common on Linux servers)
systemctl status docker
# ● docker.service - Docker Application Container Engine
# Active: inactive (dead) ← not running
sudo systemctl start docker
sudo systemctl enable docker # and start it on boot while you're at it
Forgotten enable after a reboot, a service killed by an upgrade, or the OOM killer taking down dockerd — they all land here. Check the status before anything else.
2. Docker Desktop isn't open (macOS / Windows)
With Docker Desktop, the daemon runs inside a VM, but the CLI is separate — the App can be closed while the CLI still exists, producing the identical error. Start Docker Desktop and wait for the whale icon to settle.
3. WSL2: the distro integration got switched off
Using docker inside WSL2 on Windows requires Docker Desktop's integration for that distro (Settings → Resources → WSL Integration). An upgrade that resets the toggle is a frequent visitor:
# Restart WSL, then retry
wsl --shutdown
4. A broken daemon.json prevents the daemon from starting
When /etc/docker/daemon.json has a syntax error or an invalid field, systemctl start docker appears to succeed but actually fails. Get the real reason:
journalctl -u docker --since "10 minutes ago" | tail -20
# Common output: unable to configure the Docker daemon with file ...: invalid character
Fix the JSON (note: no trailing comma after the last key) and restart. This is the classic trap when configuring registry mirrors or log rotation.
5. Wrong docker context / missing rootless env var
docker context ls
# NAME DESCRIPTION DOCKER ENDPOINT
# default * Docker Engine at unix:///var/run/... ← asterisk = current context
If the asterisk sits on a remote or stale context, even a perfectly healthy local daemon won't be reached: docker context use default.
Under rootless mode the socket lives in your user directory (/run/user/<uid>/docker.sock); a fresh SSH session without export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock will probe a system socket that doesn't exist.
The diagnostic route (two minutes, top to bottom)
# 1. Service status
systemctl status docker
# 2. Not active? Read the logs for the cause of death
journalctl -u docker -n 30
# 3. Service fine but still failing? Check socket and context
ls -l /var/run/docker.sock
docker context ls
# 4. Everything normal? Ask the daemon directly
sudo curl -s --unix-socket /var/run/docker.sock http://localhost/version | head -c 200
If step 4 returns JSON, the daemon is alive — the problem is your user's permission. See: Docker socket permission denied.
Telling the neighboring errors apart
| Error | Meaning | Guide | |---|---|---| | Cannot connect to the Docker daemon | daemon not running / unreachable | this post | | permission denied ... docker.sock | socket exists, your user lacks access | permissions post | | no space left on device | daemon alive, disk full | disk cleanup post | | port is already allocated | daemon alive, port taken | port conflict post |
Checklist
systemctl status docker— is the service active?- macOS/Windows — is Docker Desktop running? Is WSL integration on?
journalctl -u docker -n 30— any daemon.json syntax errors?docker context ls— is the asterisk on default?- rootless — is
DOCKER_HOSTset for this session?
Provided by ToolVault. Related tools: Dockerfile Generator, Linux Cheatsheet. Related reading: Docker socket permissions, Port already in use (EADDRINUSE). See the homepage for more developer tools.
Related Tools
Related Articles
Permission denied (publickey): 6 Reasons Git Push Fails Over SSH (and the Fix for Each)
git clone or push rejected with Permission denied (publickey) fatal: Could not read from remote repository? Covers missing keygen, key not loaded in the agent, public key not added to GitHub/GitLab, multi-account key routing with ~/.ssh/config, deploy key limits, and wrong remote URLs — with ssh -v diagnostics.
error:0308010C digital envelope routines::unsupported — Fixing Node 17+ Breakage in Older Projects
Node 17+ crashes webpack 4 builds with error:0308010C:digital envelope routines::unsupported because OpenSSL 3.0 removed MD4. Three fixes compared: --openssl-legacy-provider quick unblock, upgrading to webpack 5 as the real fix, and pinning Node 16 as a stopgap.
ECONNREFUSED: Connection Refused — 5 Causes Explained (Including Docker)
Node, Java, or curl reporting connect ECONNREFUSED 127.0.0.1:3306? It means nothing is listening on that port. Covers service not running, wrong port, 127.0.0.1-only binding, Docker container networking, and firewall REJECT rules — with ss/lsof diagnostic commands.