The docker command cannot reach the Docker daemon
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Short answer
This error means the docker client could not talk to a running daemon. Run docker info first. Either the daemon is stopped (start the service on Linux, or open Docker Desktop on macOS), or the client points somewhere else because DOCKER_HOST is set, or the default socket link is missing on macOS.
Fix it fast
1Find out which cause you have
Ask the client what it is talking to and whether it gets an answer. The Server section is missing or the command errors when the daemon is unreachable.
docker info env | grep DOCKER_HOST2Match what you see, then jump to its fix
- 1
The error names unix:///var/run/docker.sock and DOCKER_HOST is emptyThe daemon service is not running (Linux)Fix - 2
The host in the error message is not the local socket you expectedDOCKER_HOST points at a host or socket that is not thereFix - 3
The error mentions a socket under your home folder, such as ~/.docker/run/docker.sockDocker Desktop is not running (macOS)Fix - 4
docker works in the terminal, but another tool or SDK reports the /var/run/docker.sock errorA tool expects /var/run/docker.sock but the macOS link is offFix
- 1
What does the error look like?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Cannot connect to the Docker daemon at unix:///Users/<user>/.docker/run/docker.sock. Is the docker daemon running?
Cause 1 of 4
The daemon service is not running (Linux)
1Check
Ask systemd whether the docker service is active.
sudo systemctl status docker2Fix
Start the service. If it fails to start, the status output and the service log say why.
sudo systemctl start docker
sudo systemctl enable docker.service containerd.service3Verify
The Server section now prints, and a test container runs.
docker info
sudo docker run hello-worldConfirmed by docs.docker.com
Cause 2 of 4
DOCKER_HOST points at a host or socket that is not there
1Check
A DOCKER_HOST left over in a shell profile or CI variable sends the client to another daemon.
env | grep DOCKER_HOST2Fix
Unset it for this shell, then remove the line from the profile file that sets it (for example ~/.bashrc or ~/.profile).
unset DOCKER_HOST3Verify
docker info now answers from the local daemon.
docker infoConfirmed by docs.docker.com
Cause 3 of 4
Docker Desktop is not running (macOS)
1Check
Docker Desktop must be open, and the CLI takes its socket path from the current context, which starts as desktop-linux.
docker context ls
ls -l ~/.docker/run/docker.sock2Fix
Start Docker Desktop from Applications and wait until it reports that it is running. If the context in use is not desktop-linux, switch to it.
open -a Docker
docker context use desktop-linux3Verify
The CLI reaches the Desktop engine.
docker infoConfirmed by docs.docker.com
Cause 4 of 4
A tool expects /var/run/docker.sock but the macOS link is off
1Check
Docker Desktop only creates the /var/run/docker.sock symlink when the default Docker socket option in Settings > Advanced is enabled.
ls -l /var/run/docker.sock2Fix
Turn that option on in Docker Desktop. If you leave it off, point the tool at the real socket with DOCKER_HOST.
export DOCKER_HOST="unix://$HOME/.docker/run/docker.sock"3Verify
The tool connects, and the socket path resolves.
docker -H "$DOCKER_HOST" infoConfirmed by docs.docker.com
How do I stop it coming back?
- Keep DOCKER_HOST out of shell profiles unless you really use a remote engine; set it per command or per project instead.
- On Linux, enable the docker service so it starts at boot.
- On a Mac, start Docker Desktop before scripts that call docker, and let CI wait for docker info to succeed.
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
Docker says permission denied when your user runs a command
Got permission denied while trying to connect to the Docker daemon socket
Your user is not allowed to open /var/run/docker.sock.
3 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 fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix