This error is almost never a sign that Docker is broken. It is the Docker command line tool reporting that it walked up to a door, a Unix socket at /var/run/docker.sock, and either found nobody behind it or was not allowed to knock. Everything you need to fix it follows from that one picture.
The full message reads "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" The question at the end is a guess, and in roughly half the cases people hit on a fresh machine the guess is wrong: the daemon is running, and the real problem is permissions or an address. So do not reinstall anything yet. Work through four checks in a fixed order, because each one rules out a whole class of causes and the order matches how often each class shows up.
What the message is really telling you
Docker is two programs pretending to be one. When you type docker ps, the binary called docker does almost nothing itself. It formats an HTTP request and sends it to the Docker Engine API, served by a separate background process. That process does the real work of pulling images, creating containers and managing networks. The error appears at the exact moment the first request fails to reach it.
Three terms make the rest of this guide easier to follow.
Docker daemon (dockerd): the long-running background service that owns containers, images, volumes and networks on a host. On most Linux installs systemd starts it through a unit called docker.service, and it runs as root.
Unix domain socket: a special file that two processes on the same machine use to talk, much like a network port that exists only on the local filesystem. Access to it is controlled by ordinary file ownership and permission bits, which is why a permissions problem can look like a connectivity problem.
Docker context: a named bundle of connection settings stored by the CLI, saying which endpoint to talk to. The context called default points at unix:///var/run/docker.sock, but contexts can point at other sockets, remote hosts over SSH, or Docker Desktop's own socket.
With those in mind, the error can only mean one of four things. The daemon is not running, so the socket file does not exist or nothing listens on it. The daemon is running, but your user cannot open the socket. The client is pointed at a different address from the one where the daemon listens. Or you are in a different environment than you think, such as a container, a CI job or a WSL distribution without Docker integration.
There is also a sibling error worth recognising: "permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock". That wording tells you the socket exists and the daemon is very likely alive, which lets you skip straight to the permissions check. The plain "Cannot connect" wording is less specific and needs the full sequence.
Check one: is dockerd actually running
Start with the daemon, because no other fix matters if it is down. On any systemd-based distribution, ask systemd directly.
sudo systemctl status docker
sudo systemctl status docker.socket
sudo journalctl -u docker --since "30 min ago" --no-pager
If the status line says inactive (dead) and the unit is disabled, the daemon simply was never started, which is common straight after installing from packages. Start it and enable it for future boots with sudo systemctl enable --now docker. Many installs also ship docker.socket, a socket activation unit: systemd holds the socket open and starts dockerd on the first connection. If docker.socket is active but docker.service keeps failing, the socket file exists yet every request dies, which produces the same error with a confusing twist.
If the unit shows failed or keeps restarting, read the journal. The two most frequent causes on servers are a broken /etc/docker/daemon.json and a setting declared twice. A missing comma in daemon.json stops the daemon at startup, and the journal says so in plain words.
Recent versions of dockerd can check the file without starting, using dockerd --validate with the config file path. The duplicate problem looks like "the following directives are specified both as a flag and in the configuration file", usually because someone added "hosts" to daemon.json while the systemd unit already passes -H fd:// on the command line. Remove one of the two.
sudo dockerd --validate --config-file /etc/docker/daemon.json
ls -l /var/run/docker.sock
Other startup killers show up in the same journal: a storage driver that does not match what is already in /var/lib/docker, a filesystem with no free space, or a second Docker installed from a different source (for example a snap package next to the distribution package) fighting over the same paths. Pick one install and remove the other completely.
On a desktop machine the daemon lives inside Docker Desktop's virtual machine. If Docker Desktop is closed, still starting, or paused to save resources, the socket is not served. Open the application and wait for the engine status to turn green before you debug anything else.
Check two: can your user open the socket
If the daemon is running, look at the socket file and at who you are. On a standard Linux install the socket belongs to root and to a group called docker, with mode 0660. Members of the docker group can use it without sudo. Everyone else gets refused.
ls -l /var/run/docker.sock
id
getent group docker
sudo usermod -aG docker "$USER"
newgrp docker
Here is a worked example with real numbers from a typical fresh server. The ls -l output shows srw-rw---- 1 root docker 0 for the socket. The leading s marks a socket. The mode 0660 splits into three octal digits: 6 for the owner (read 4 plus write 2), 6 for the group, 0 for everyone else.
The getent line prints docker:x:998:alice, so the docker group has numeric id 998 and alice is listed as a member. Yet alice still sees the error. Her id output reads uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo), with no 998 anywhere.
The reason is timing: alice opened her SSH session at 09:00, and the admin ran usermod at 09:20. A process keeps the group list it received at login, and every shell started from that session inherits the old list of 2 groups. The membership exists in /etc/group but not in her running session. Logging out and back in, or running newgrp docker for a single shell, gives her a process with group 998 and the error disappears. Twenty minutes of confusion, zero bytes of configuration wrong.
Two variations of this check are common. If the socket's group is root instead of docker, the docker group probably did not exist when the package was installed; create it, restart the daemon and the socket comes back with the right group. If you are on a hardened host where nobody is allowed into the docker group, use sudo docker, and accept that every command needs elevation.
Keep in mind why the group is restricted. Docker's own documentation warns that membership in the docker group grants privileges equivalent to root, because anyone who can talk to the daemon can start a container that mounts the host filesystem. Adding a user to the group is a security decision, so treat it like handing out sudo.
Check three: is the client aimed at the right address
When the daemon runs and permissions look correct, the client is often looking somewhere else. Two settings decide where it goes, and an environment variable beats a context.
echo "$DOCKER_HOST"
echo "$DOCKER_CONTEXT"
docker context ls
docker context use default
unset DOCKER_HOST
DOCKER_HOST is the usual culprit. A shell profile, a .env file loaded by a tool, or an old tutorial may have set it to a TCP address such as tcp://localhost:2375 or to a rootless socket. If it is set, the CLI ignores the context entirely.
Unset it, open a new shell, and retest. Then run docker context ls: the asterisk marks the active context. If it points at desktop-linux, a remote host over SSH, or a context left over from a cloud tool, switch back with docker context use default.
Rootless Docker changes the address by design. In rootless mode the daemon runs as your own user and listens on a socket under your runtime directory, for example /run/user/1000/docker.sock for user id 1000, while /var/run/docker.sock may not exist at all. The rootless setup tool prints the DOCKER_HOST value you need, and the daemon itself runs as a user service, so check it with systemctl --user status docker rather than the system unit.
Sudo creates its own trap. Most sudo configurations reset the environment, so sudo docker ps ignores your DOCKER_HOST and goes to the default socket, while plain docker ps follows the variable. If one of the two works and the other fails, compare where each is pointed before changing anything.
The last group of cases is about environment. Inside a container, /var/run/docker.sock exists only if someone mounted it from the host with -v /var/run/docker.sock:/var/run/docker.sock. In CI, a job that uses a Docker CLI image without a Docker-in-Docker service, or without DOCKER_HOST pointed at that service, fails with exactly this message on the first build step. On Windows, a WSL 2 distribution only reaches Docker Desktop's engine when WSL integration is enabled for that particular distribution in Docker Desktop's settings.
Questions people ask after fixing the docker.sock error
Why does docker version print a Client section and then fail? The client section is built locally from the binary itself, so it always prints. The Server section requires a round trip through the socket, and that is where the error appears. It makes docker version a quick two-in-one test: if the Client block is missing, the problem is the CLI install, not the daemon.
Can I just run chmod 666 on the socket? It will work until the next daemon restart, because dockerd recreates the socket with its own ownership and mode each time it starts. Meanwhile every local account on the machine, including service users, gets root-equivalent control of the host. Fix group membership instead.
Does Podman produce the same message? Yes, if you use the Docker CLI or the podman-docker compatibility package against Podman. Podman has no always-on daemon, so the API socket must be enabled first, typically with systemctl --user enable --now podman.socket, and DOCKER_HOST pointed at the socket under the runtime directory, for example /run/user/1000/podman/podman.sock.
Is the error ever caused by a full disk? Indirectly. If /var/lib/docker sits on a filesystem with 0 bytes free, dockerd can fail during startup while it initialises its storage driver, and then the socket never appears. The journal shows the real cause, so check df -h on that mount whenever the daemon refuses to start for no obvious reason.
The verdict comes down to one trade-off between convenience and blast radius. The docker group is the most convenient fix and the one most tutorials give, and on a personal laptop or a single-purpose build box it is reasonable. On a shared server it hands root to everyone in the group, so sudo docker, slower as it is, is the honest choice there.
Rootless mode sits in between: it removes the root-equivalence problem at the cost of a different socket path, some networking and storage limitations, and one more DOCKER_HOST value to remember. Pick by who else can log in to the machine, not by which fix makes the error vanish fastest.