Sub topic 11
Troubleshooting common problems
This chapter assumes you have tried an install from an earlier chapter, are comfortable reading terminal output, and can use sudo. Most failures come from a few causes: the daemon isn't running, your user can't reach it, or the package source is wrong. Work through them in that order.
Start with what docker version says
docker version prints a Client section and a Server section. The client is the CLI. The server is the daemon. The output tells you which side is broken.
docker version
docker context ls
echo "DOCKER_HOST=${DOCKER_HOST:-unset}"- If the Client section prints and the Server section shows an error, the CLI works but cannot reach the daemon.
- If nothing prints, the CLI is not installed or not on your
PATH. - If the context list marks an unexpected context with
*, the CLI is talking to a different daemon than you think. This happens when Docker Desktop and Docker Engine are both installed on one Linux machine.
Permission denied on the Docker socket
The error looks like this:
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockThe daemon listens on a Unix socket owned by root and the docker group. Your user must be in that group, and your current session must know about it.
ls -l /var/run/docker.sock
id -nGIf docker is missing from the id output, run sudo usermod -aG docker $USER. Group changes apply only to new sessions. Run newgrp docker in the current shell, or log out and back in. If you added the group but the error persists, a terminal that was open before the change is the usual cause.
A related error appears if you once ran sudo docker and Docker created ~/.docker as root. The CLI then reports permission problems on ~/.docker/config.json. Fix the ownership:
sudo chown -R "$USER":"$USER" "$HOME/.docker"Cannot connect to the Docker daemon
The error reads Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? This means the socket exists but nothing is serving it, or the socket is missing.
On Docker Engine for Linux, check the service and its log:
sudo systemctl status docker --no-pager
sudo journalctl -u docker --no-pager -n 50
sudo systemctl enable --now docker.serviceThe log usually names the cause, such as a malformed /etc/docker/daemon.json or a storage driver problem. A JSON syntax error in daemon.json stops the daemon from starting at all.
With Docker Desktop, the daemon runs inside a virtual machine. Open the application and wait until it reports that Docker is running. If it won't start, check these causes:
- Hardware virtualization is turned off in the BIOS or UEFI.
- On Windows, WSL 2 is missing or outdated. Run
wsl --updateand restart Docker Desktop. - On Linux, your user cannot use KVM. Check
ls -l /dev/kvmand thekvmgroup.
Package errors with apt
Typical symptoms are NO_PUBKEY, 404 Not Found on the repository URL, or Unable to locate package docker-ce. Inspect the repository file and the key:
cat /etc/apt/sources.list.d/docker.list
ls -l /etc/apt/keyrings/docker.asc
apt-cache policy docker-ceCheck these points:
- The key file must be readable by all users (
chmod a+r). An unreadable key causes signature errors. - The codename in
docker.listmust be a release Docker publishes. Ubuntu derivatives such as Linux Mint report their own codename inVERSION_CODENAME. The command from the install chapter prefersUBUNTU_CODENAMEfor this reason. - You must run
sudo apt-get updateafter creating the file. Without it,apt-cache policyshows no candidate. - The candidate version should come from
download.docker.com. If it comes from an Ubuntu mirror, apt is not using Docker's repository.
Old or unofficial packages can also conflict. Remove them before installing, and note that this does not delete data in /var/lib/docker:
sudo apt-get remove docker.io docker-compose docker-doc podman-docker containerd runcImage pulls fail
If docker run hello-world reports a timeout, a TLS error, or toomanyrequests, the installation is probably fine and the problem is the network. Test name resolution and registry access first:
curl -I https://registry-1.docker.io/v2/A 401 response is normal here and shows the registry is reachable. Behind a corporate proxy, the daemon needs its own proxy settings, because your shell's HTTP_PROXY variable does not apply to it. Anonymous pulls are rate limited, so logging in with docker login raises the limit.
Exercise
After running sudo usermod -aG docker $USER, docker ps still says permission denied on the socket in the same terminal. What is the likely cause, and what are two ways to fix it?
Show answer
Group membership is read when a session starts, so the open shell does not have the new group. Run newgrp docker in that shell, or log out and back in, then confirm with id -nG.