What the message looks like
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Common causes
- The Docker service is not started or exited after an error, for instance because of a broken
/etc/docker/daemon.json. - Docker Desktop is not running (macOS, Windows) or the Linux VM behind it has not come up yet.
DOCKER_HOSTor a Docker context points to another socket or host that is unreachable.- With rootless Docker the socket lives under
$XDG_RUNTIME_DIR/docker.sock, but the client looks at the default path. - The socket
/var/run/docker.sockdoes not exist because the service has not finished starting after boot.
Check
- Service status
systemctl status docker --no-pager | head -n 15 - Latest daemon log lines
- Does the socket exist and who owns it?
ls -l /var/run/docker.sock - Check the active context and DOCKER_HOST
docker context ls; env | grep -i '^DOCKER'
Fix
- Start the service and enable it permanently:
sudo systemctl enable --now docker. - If it will not start, read the cause in the journal. If
daemon.jsonis broken, check it withpython3 -m json.tool /etc/docker/daemon.jsonand fix it. - Remove a stray variable with
unset DOCKER_HOSTand switch back to the local daemon viadocker context use default. - On macOS or Windows, start Docker Desktop and wait until it shows as running.
- If you get "permission denied" instead, the daemon is there but the user is not in the
dockergroup:sudo usermod -aG docker $USER, then log in again.
Typical scenario
A server was updated with apt upgrade, and afterwards every docker ps fails with the daemon message. systemctl status docker shows "failed", and the journal reports a syntax error in /etc/docker/daemon.json, where a comma had been forgotten earlier. After fixing it and running systemctl restart docker the containers come back.
FAQ
How does this differ from "permission denied"?
With "Cannot connect … Is the docker daemon running?" the daemon or socket is unreachable. With "permission denied while trying to connect" the socket exists but the user may not use it.
Is sudo docker a good fix?
It is a valid test: if it works with sudo, the daemon runs and only the group membership is missing. Long-term the docker group is more convenient but effectively grants the user root rights.
Will my containers start on their own after the fix?
Only if they have a restart policy such as unless-stopped or always. Without one they stay stopped and must be brought up with docker start or docker compose up -d.
Why does it only work in some terminals on my Mac?
An environment variable such as DOCKER_HOST or a different Docker context may be active there. docker context ls marks the active context with an asterisk.
Can I start the daemon in the foreground to see errors?
Yes: stop the service and run sudo dockerd. Configuration and startup errors then show up directly in the terminal. Stop it with Ctrl+C and go back to the service.