Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When a docker command prints "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?", the client could not reach a daemon at the address it uses. Docker's troubleshooting page gives two reasons: the daemon "isn't running on your system", or the client is trying to reach a daemon on a different host that is unreachable. Check which before you start anything.

What the error means

The message comes from the Docker client library, and this wording is taken from its source code (the moby project, release tag v28.5.2), not from a documentation page. The source builds it in two forms. With an address it uses the format "Cannot connect to the Docker daemon at %s. Is the docker daemon running?", where %s is replaced by the address the client tried. When the address is empty it uses "Cannot connect to the Docker daemon. Is the docker daemon running on this host?". Docker's troubleshooting page prints an older wording, "Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?", and explains it the same way.

By default the client uses the Unix socket unix:///var/run/docker.sock on Linux. Three things can override that: the DOCKER_HOST environment variable ("Daemon socket to connect to"), the -H flag, and a Docker context. The contexts page says an active context is used "unless overridden with environment variables such as DOCKER_HOST and DOCKER_CONTEXT, or on the command-line with the --context and --host flags."

If the message says "permission denied" instead, the daemon is running and the problem is access to its socket. That is a different fault.

Likely causes

Cause What you see How to confirm
Daemon is stopped systemctl is-active docker prints a state other than active docker info fails the same way
Daemon failed to start The service is failed; the journal names an error journalctl -xu docker.service
daemon.json has an error or conflicts with a service flag A message such as "unable to configure the Docker daemon with file /etc/docker/daemon.json" dockerd --validate --config-file=/etc/docker/daemon.json and the journal
DOCKER_HOST set to another host The message names a tcp:// or ssh:// address The DOCKER_HOST check in step 3 below prints a value
Active context points elsewhere The message names the context's address docker context ls shows the asterisk on another context
Daemon stopped by the kernel for lack of memory The daemon stopped without a service change journalctl -k for out-of-memory messages

Prove the cause before changing anything

All of these only read.

  1. Ask Docker, then the service. The troubleshooting page calls docker info the "operating-system independent way" to check, and lists sudo systemctl is-active docker as one of the operating system tools:
docker info
systemctl is-active docker
  1. Read the daemon log. The Docker logs page gives journalctl -xu docker.service for Linux:
journalctl -xu docker.service

A good result is a recent start with no error. A bad result is an error line near the last start attempt.

  1. Check the client's target:
env | grep DOCKER_HOST
docker context ls

If the first command prints a value, the client is set to connect to a daemon on that host. If it prints nothing, the client uses the local host. The context list shows the active context with an asterisk.

  1. Validate the daemon configuration file without starting the daemon:
dockerd --validate --config-file=/etc/docker/daemon.json

The dockerd reference says this validates a configuration file "without starting the Docker daemon" and returns a non-zero exit code for an invalid file. Its example prints "configuration OK" for a valid file.

  1. Only if the daemon stopped by itself, read kernel messages. The Docker page says the daemon "might be stopped by the kernel OOM killer":
journalctl -k

Example (illustrative): On web01 an engineer adds "hosts": ["tcp://127.0.0.1:2376"] to /etc/docker/daemon.json and restarts Docker. Every docker command now prints the error. systemctl is-active docker does not print active. The journal shows the message the Docker page gives for this case (the page wraps it over three lines): "unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: hosts: (from flag: [unix:///var/run/docker.sock], from file: [tcp://127.0.0.1:2376])". The page explains that on Debian and Ubuntu with systemd, a -H flag is always used when starting dockerd, so a hosts entry in the file conflicts with it. Removing the hosts entry from the file fixes it.

Fix

The client points at the wrong place

If env | grep DOCKER_HOST printed a value you did not intend, the page's remedy is unset DOCKER_HOST, and it adds that you may need to edit files such as ~/.bashrc or ~/.profile if the variable is set there.

First print the current value and keep the output (the example below assumes it was DOCKER_HOST=tcp://198.51.100.20:2376):

env | grep DOCKER_HOST

Risk: the next command makes the client use the local daemon. If you meant to manage a remote host, later commands will act on this machine's containers instead.

Run this in the same shell:

unset DOCKER_HOST

To undo it: set the saved value again in that shell:

export DOCKER_HOST=tcp://198.51.100.20:2376

If the active context is the problem, the contexts page documents docker context use.

First list the contexts and keep the output (the example below assumes the asterisk was on docker-test):

docker context ls

Risk: the next command makes later docker commands go to the default context's daemon. Commands meant for the other context's host will run here.

docker context use default

To undo it: select the saved context again. DOCKER_CONTEXT set in the environment overrides this setting, so check it too.

docker context use docker-test

The daemon configuration is wrong

Use this section only if /etc/docker/daemon.json exists; check with ls -l /etc/docker/daemon.json. If the file does not exist, nothing in it can be the cause, so go to the next section. First save the current file:

cp -p /etc/docker/daemon.json /etc/docker/daemon.json.2026-11-22

Risk: the next edit changes the file the daemon reads at start. A mistake keeps Docker from starting and keeps every container on this host down.

Edit /etc/docker/daemon.json. If the journal names a duplicated option such as hosts, remove it from the file. Changing the service's own startup flags is a separate change that needs its own saved copy and back-out, and this section does not cover it. Then validate:

dockerd --validate --config-file=/etc/docker/daemon.json

A file that passes prints "configuration OK" and exits with 0. The daemon reports a conflict between the file and a service flag when it starts. This section does not start the daemon: continue with the next section, "The daemon is stopped", and read the journal after you start it.

To undo it: put the saved file back under its original name and validate it:

cp -p /etc/docker/daemon.json.2026-11-22 /etc/docker/daemon.json
dockerd --validate --config-file=/etc/docker/daemon.json

The daemon is stopped

First save the log so the failure is on record:

journalctl -u docker.service > docker-journal-2026-11-22.txt

Disruptive step: the next command starts the Docker daemon. Containers created with a restart policy such as always can start again as soon as the daemon is up, and the restart policies page says always restarts a container if it stops.

Start it, then check:

systemctl start docker
systemctl is-active docker

To undo it: stop the service, and read any warning it prints about units that can trigger the service again (the systemctl manual says such a warning names them). Running containers may stop with the daemon. The restart policies page says live restore lets you "keep your containers running during a Docker upgrade"; it does not describe what a plain stop does.

systemctl stop docker

If the daemon is not enabled at boot, the post-install page gives sudo systemctl enable docker.service; it also says Docker starts on boot by default on Debian and Ubuntu. First print the current setting and keep the output:

systemctl is-enabled docker

Disruptive step: the next command makes Docker start at every boot. The systemctl manual says enable does not start the unit now.

systemctl enable docker.service

To undo it: only if the noted output was disabled, run systemctl disable docker.service.

Confirm the fix

  1. docker info prints server details instead of the error.
  2. systemctl is-active docker prints active.
  3. docker ps lists the containers you expect.
  4. After a reboot, the daemon is running without anyone starting it.

What to watch afterwards

  • Validate daemon.json with dockerd --validate before every restart of Docker.
  • Check env | grep DOCKER_HOST after changing shell profiles or deployment scripts.
  • Watch memory on the host. Docker's page warns that the kernel OOM killer can stop the daemon.
  • Read journalctl -xu docker.service after any failed start before trying again.

Risks and limits

  • These commands have not been run or lab-tested.
  • Docker Desktop, rootless mode and Windows hosts use different sockets and paths and are not covered.
  • Stopping the daemon may stop the containers it runs; the cited page covers live restore only for upgrades.
  • The conflict check between the file and service flags happens at start. dockerd --validate checks the file.

Sources