Skip to content
Log In Sign Up info@muvcloud.com

What the Error Means

The docker command is only a client. It sends every request to the Docker daemon, dockerd, through a socket, by default /var/run/docker.sock. The message Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? means the client found nothing listening at the address it used. A different message, which says permission denied while trying to connect to the Docker daemon socket, means the daemon runs but your user may not use the socket. Work through the causes in this order.

Cause 1: The Docker Service Is Not Running

systemctl status docker
sudo systemctl start docker
sudo systemctl enable docker

On Debian and Ubuntu the service starts after installation. On AlmaLinux and Rocky Linux it does not; sudo systemctl enable --now docker starts it and enables it at boot. If it fails to start, read the journal:

sudo journalctl -u docker -b --no-pager | tail -n 30

Frequent reasons are a syntax error in /etc/docker/daemon.json, such as a missing comma or quote (sudo dockerd --validate checks the file), a full disk (check df -h /var/lib/docker), and a stopped containerd service. Fix the cause and start Docker again. More on reading the journal is in the journalctl guide, and on service states in how to list services with systemctl.

Cause 2: Your User May Not Use the Socket

ls -l /var/run/docker.sock
id
sudo docker ps

The socket belongs to root and the group docker, and only those two may use it. If sudo docker ps works and docker ps fails, your user is not in the group, or was added but has not logged in again: group membership is read at login. Add the user and apply it in the current shell:

sudo usermod -aG docker $USER
newgrp docker

Membership of the docker group equals root on the host. Read how to run Docker without sudo before you add anyone.

Cause 3: DOCKER_HOST or a Docker Context

env | grep DOCKER_
docker context ls
unset DOCKER_HOST DOCKER_CONTEXT
docker context use default

The variables DOCKER_HOST and DOCKER_CONTEXT override the context chosen with docker context use. Without them, the client uses the current context, marked with an asterisk in docker context ls; the default context talks to /var/run/docker.sock. An old export DOCKER_HOST=… in ~/.bashrc that points to another server or a removed socket causes this error in every new shell; remove the line, as shown in the .bashrc guide.

Cause 4: Rootless Docker Uses Another Socket

A rootless daemon runs as your own user and listens on $XDG_RUNTIME_DIR/docker.sock, usually /run/user/1000/docker.sock for the user with ID 1000. Its setup creates a context named rootless, which docker context use rootless selects, or set the variable:

systemctl --user status docker
systemctl --user start docker
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock

If XDG_RUNTIME_DIR is empty, or systemctl --user says it failed to connect to the bus, you probably switched users with su or sudo -iu, which does not open a systemd user session; log in as that user over SSH instead. To start the rootless daemon at boot and keep it running after the user logs out, run sudo loginctl enable-linger deploy for that user.

Never chmod 666 the Socket

Advice found online suggests sudo chmod 666 /var/run/docker.sock. It hides the error by giving every account on the server, including the web server's user and any compromised application, full control of Docker, and that is root on the host. It does not even last: the socket is created again with its normal permissions, at the latest after a reboot. Use the docker group for trusted accounts, or sudo.

Quick Checklist

  1. Does systemctl status docker show the service as active?
  2. Does sudo docker ps work? If yes, it is a group problem.
  3. Is DOCKER_HOST empty, and is the context the one you expect?
  4. Is Docker on this server rootless, with its socket under /run/user?

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations