Docker

Cannot connect to the Docker daemon at unix:///var/run/docker.sock: causes and fix

Fix 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?' Check the service, socket and context.

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

In short

The docker command-line client could not reach the Docker daemon (dockerd) through its Unix socket at /var/run/docker.sock. The client printed the error, not the daemon. Either dockerd is not running, the socket file is missing, or the daemon is listening on a different socket than the client expects.

Likely causes

  • •The Docker service is stopped or never started. Run 'systemctl status docker'. If it shows inactive (dead) or failed, this is the cause. It is common after a fresh install, a reboot where the service was not enabled, or a package upgrade.
  • •The daemon crashed on start because of a bad config. The service shows failed and 'journalctl -u docker' contains errors about /etc/docker/daemon.json, a storage driver, or a full disk. A typo in daemon.json is the usual trigger.
  • •The daemon is listening on a different socket than the client uses. The error names the default path, so the client is using the default socket. If Docker runs rootless, the daemon listens on /run/user/<uid>/docker.sock instead. Run 'ls -l /run/user/$(id -u)/docker.sock' and 'docker context ls'. If that socket exists, the daemon is up and the client is looking in the wrong place.
  • •Docker is not installed, or runs in a different form (Snap, rootless, WSL). 'which docker' finds a client but no dockerd exists, or Docker was installed by Snap or in rootless mode. Rootless Docker uses a socket under /run/user/<uid>/docker.sock, not /var/run/docker.sock.
  • •The socket file is missing or stale. The service is running but 'ls -l /var/run/docker.sock' says no such file. This can happen if the socket unit is stopped or /var/run (a link to /run) was cleaned.

How to fix it

  1. 1. Check whether the Docker service is running

    Look at the state of the service. If it says active (running), skip to the socket step. If it says inactive or failed, continue.

    systemctl status docker --no-pager
  2. 2. Start Docker and enable it at boot

    This starts the daemon. It does not restart anything that is already running. If the daemon is down, no containers are running anyway, but containers with a restart policy will start again once it is up.

    sudo systemctl enable --now docker
  3. 3. Read the logs if it fails to start

    Look for the real reason: a JSON syntax error in /etc/docker/daemon.json, a bad storage driver, a port clash, or no free disk space.

    sudo journalctl -u docker --no-pager -n 50
    df -h /var/lib/docker
  4. 4. Validate daemon.json if the log points at it

    Check the file for syntax errors. If it is broken, fix it or move it aside (keep a copy), then start Docker again. Moving it aside drops your custom settings until you restore them.

    sudo python3 -m json.tool /etc/docker/daemon.json
    sudo mv /etc/docker/daemon.json /etc/docker/daemon.json.bak
    sudo systemctl restart docker
  5. 5. Confirm the socket exists

    You should see a socket file (it starts with 's') owned by root. If the socket is missing but the service is active, start the socket unit.

    ls -l /var/run/docker.sock
    sudo systemctl enable --now docker.socket
  6. 6. Point the client at the right socket if the daemon runs rootless

    If Docker runs rootless, the daemon does not use /var/run/docker.sock. Set DOCKER_HOST to the rootless socket for your user. Add the line to your shell profile to keep it.

    export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
    docker context ls
  7. 7. Install Docker if it is missing

    If 'systemctl status docker' says the unit could not be found, install Docker Engine from the official Docker repository. On Ubuntu/Debian the package is docker-ce, on RHEL-family systems it is also docker-ce from Docker's repo. Distro packages named docker.io (Debian/Ubuntu) also work.

    # Ubuntu/Debian (distro package)
    sudo apt-get update && sudo apt-get install -y docker.io
    # RHEL-family: add Docker's repo first, then
    sudo dnf install -y docker-ce docker-ce-cli containerd.io

Confirm it is fixed

The client should print both Client and Server sections without any connection error. If you only see the Client section followed by the error, the daemon is still unreachable.

docker version && docker run --rm hello-world

How Opservo catches it early

Opservo discovers systemd services, flags units in a failed state and services that have restarted many times, and clusters journal errors into patterns, so a stopped or flapping docker service shows up as a finding.

Last updated 2026-11-30.

FAQ

Related questions

Is the error different from 'permission denied while trying to connect to the Docker daemon socket'?+

Yes. 'Permission denied' means the socket exists and your user is blocked, which is fixed with access to the docker group or sudo. 'Cannot connect ... Is the docker daemon running?' means nothing answered at that address, so check the service and the socket.

Do I lose my containers and images if I restart Docker?+

No. Images, volumes and stopped containers live in /var/lib/docker and survive a restart. Running containers stop unless they use a restart policy or live-restore is enabled in daemon.json.

Does this error happen on WSL or Docker Desktop?+

Yes. On those setups the daemon runs inside Docker Desktop, so start Docker Desktop and enable WSL integration for your distro. There is no systemd docker service to start in that case.

Cannot connect to the Docker daemon