Linux  ·  high  ·  Containers & Kubernetes

"Cannot connect to the Docker daemon"

Either the daemon is not running, or the user has no permission to reach its socket.

What you see

Every docker command fails with the same message. The wording differs subtly between the two causes and that difference is the diagnosis.

What is actually wrong

"Is the docker daemon running?" means it is not. "Permission denied while trying to connect" means it is, and this user cannot reach the socket.

Codes and articles

Cannot connect to the Docker daemondocker.sockpermission denied while trying to connectIs the docker daemon running

Fixes (2)

Grant socket access, understanding what it means
Root shell10 minuteshigh riskreversible

Permission denied.

  1. Confirm the socket and its ownership.

    Shell
    ls -l /var/run/docker.sockid
  2. Understand what adding a user to the docker group grants before doing it: it is equivalent to root. Anyone in that group can start a container that mounts the host filesystem and read or write anything on it.

    This is presented everywhere as a convenience step and it is a privilege grant. On a shared or production machine it deserves a decision, not a reflex.

  3. Where that is acceptable, add the user and start a new session.

    Shell
    sudo usermod -aG docker $USERnewgrp dockerdocker info | head -5
  4. Where it is not, use sudo for docker commands, or run rootless Docker, which gives the same convenience without host-level privilege.

    Shell
    dockerd-rootless-setuptool.sh installexport DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
  5. For Podman, no daemon and no group are involved at all — rootless is the default.

    Shell
    podman info | head -5
Confirm it workeddocker ps works as the intended user.
Shell
docker ps
If you need to undo itsudo gpasswd -d $USER docker removes the group membership.
Find out why the daemon will not run
Root shell25 minutesmedium riskreversible

The daemon is not running.

  1. Read why it stopped.

    Shell
    systemctl status docker --no-pager -lsudo journalctl -u docker -n 60 --no-pager
  2. Check the disk. A full /var stops the daemon and is the most common cause.

    Shell
    df -h /var/lib/dockersudo du -sh /var/lib/docker/* 2>/dev/null | sort -h | tail

    Docker stores images, containers and volumes under /var/lib/docker and fills a small root partition quietly. The daemon then refuses to start with an error that does not mention disk space.

  3. Validate the daemon configuration — a JSON syntax error stops it starting with a message that is easy to miss.

    Shell
    sudo cat /etc/docker/daemon.json | python3 -m json.tool
  4. Reclaim space carefully. Check what would be removed before removing it.

    Shell
    docker system dfdocker system prune -a --dry-run 2>/dev/null || docker system df -v | head -30
  5. Prune, being aware that -a removes every image not used by a running container, including ones you would have to rebuild or re-pull.

    Shell
    docker system prune -fdocker image prune -a -f

    Volumes are not removed by default and that is deliberate — they hold data. Adding --volumes to a prune is how databases get deleted, so it should never be a reflex.

Confirm it workedThe daemon starts and stays running.
Shell
systemctl is-active docker && docker info | grep -E 'Server Version|Storage Driver|Docker Root'
If you need to undo itRestore daemon.json from a backup if it was edited. Pruned images can be pulled again; pruned volumes cannot.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.