Fixing `Cannot connect to the Docker daemon at unix:///var/run/docker.sock` on Ubuntu 22.04
This happened on a self-hosted runner that had been fine for months. A routine apt upgrade pulled in a new Docker Engine package, and the next job died before it even got to building an image. The error was one of those that looks simple and sends you down the wrong path.
## The error
$ docker info
Client:
Version: 25.0.3
Context: default
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I checked the service, which is where everyone tells you to look first:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2026-04-08 09:14:02 UTC; 3min ago
Process: 812 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
So the daemon was failing to start. The docker info message was technically true but uselessly vague.
## Finding the real cause
The unit status only shows the exit code. The actual reason is in the journal:
journalctl -u docker.service --since "10 min ago" -n 50 --no-pagerdockerd[812]: failed to start daemon: error initializing graphdriver: overlay2: backending overlay2 is not supported with the current storage driver configuration
Turns out the update had left a stale /var/lib/docker from an older storage setup and overlay2 couldn't initialize over it. Not a socket problem at all.
## The fix, and the part I'd skip next time
I stopped the service, moved the data directory aside, and let Docker recreate it:
sudo systemctl stop docker
sudo mv /var/lib/docker /var/lib/docker.bak
sudo systemctl start docker
$ docker info --format '{{.ServerVersion}}'
25.0.3
That worked. Container images were gone, which was fine on a runner, but on a machine with state you'd want to export them first. I should have checked dockerd logs before touching permissions, but I wasted twenty minutes on usermod -aG docker first because that's the usual answer to this error and it wasn't the answer here.
A thing I should have tried earlier: dockerd --validate --config-file=/etc/docker/daemon.json would have told me the config was fine and pointed me to the storage layer. I didn't know that flag existed until someone on our infra channel mentioned it. Also worth noting that our runner images are rebuilt weekly from a base that pins Docker 25, so the apt upgrade wasn't the cause by itself. It just exposed a /var/lib/docker that had been carried forward from a Docker 20 install with a different graphdriver. Old state, new binary, bad combination.
If the daemon is actually running and you still get the socket message, then it is a group problem:
sudo usermod -aG docker "$USER"
You need to log out and back in for that to take effect. newgrp docker works for the current shell if you can't do that.
## Why I'm writing this down
The confusing bit is that one error message covers at least three unrelated causes: daemon down, socket permissions, and daemon failing to initialize. systemctl status plus journalctl distinguishes them in about thirty seconds. I've added both to our runner's health check now, so the next update failure shows the real line in the job log instead of the generic one.