Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

The docker command cannot reach the Docker daemon

ErrorCannot 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.

  • Applies to Docker Engine 28, Docker Desktop 4 for macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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_HOST
  2. 2Match what you see, then jump to its fix

    1. 1The error names unix:///var/run/docker.sock and DOCKER_HOST is emptyThe daemon service is not running (Linux)Fix
    2. 2The host in the error message is not the local socket you expectedDOCKER_HOST points at a host or socket that is not thereFix
    3. 3The error mentions a socket under your home folder, such as ~/.docker/run/docker.sockDocker Desktop is not running (macOS)Fix
    4. 4docker 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

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 docker

2Fix

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.service

3Verify

The Server section now prints, and a test container runs.

docker info
sudo docker run hello-world

Confirmed by docs.docker.com

Did this fix it?

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_HOST

2Fix

Unset it for this shell, then remove the line from the profile file that sets it (for example ~/.bashrc or ~/.profile).

unset DOCKER_HOST

3Verify

docker info now answers from the local daemon.

docker info

Confirmed by docs.docker.com

Did this fix it?

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.sock

2Fix

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-linux

3Verify

The CLI reaches the Desktop engine.

docker info

Confirmed by docs.docker.com

Did this fix it?

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.sock

2Fix

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" info

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.