Docker Error Troubleshooting: The Complete Guide
Most Docker time is spent fighting the same handful of errors. This is the map: what each one means, the command that reveals the cause, and the fix.
Key takeaways
- Start every Docker error with docker ps -a for the exit code and docker logs for the last lines; that names most failures in seconds.
- Socket errors are permissions or a stopped daemon, exit 137 is a kill (often OOM), exit 127 is a missing command, and no space left on device means docker system df, then prune.
On this page
Start with docker ps -a for the exit code and docker logs <container> for the last lines; those two commands identify most Docker failures in seconds. Then match the error to one of four buckets: can't reach the daemon, container won't stay up, won't build or bind, or Compose wiring.
Verified against
Docker Engine 29.9 (29.9.2, released 2026-10-20), against the docs.docker.com daemon troubleshooting page, the running-containers exit status reference and the docker system df CLI reference. Checked October 2026.
The universal first move, before any specific error:
$ docker ps -a # running, or Exited with a code?
$ docker logs --tail 50 <container> # what it printed before dying
$ docker inspect --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' <container>
$ docker events # live stream of what the daemon is doing
An OOM-killed container prints 137 OOMKilled=true from the inspect line.
The error strings, at a glance
| You see | Bucket | First command | Usual fix |
|---|---|---|---|
permission denied while trying to connect to the Docker daemon socket | Daemon access | id, ls -l /var/run/docker.sock | Add user to docker group, re-login |
Cannot connect to the Docker daemon at unix:///var/run/docker.sock | Daemon access | sudo systemctl is-active docker | Start daemon, or unset DOCKER_HOST |
Exited (0) seconds after start | Won't stay up | docker logs | Run the main process in the foreground |
Exited (127), executable file not found in $PATH | Won't stay up | docker run -it --entrypoint sh <image> | Fix CMD or install the binary |
Exited (137) | Won't stay up | docker inspect for OOMKilled | Raise --memory or fix the leak |
exec format error | Won't stay up | docker image inspect architecture | Build for the host's platform |
port is already allocated | Build or bind | docker ps --filter publish=8080 | Stop the holder or change the host port |
no space left on device | Build or bind | docker system df | Prune build cache and unused images |
Temporary failure in name resolution | Build or bind | cat /etc/resolv.conf | Set "dns" in daemon.json |
Bucket 1: "I can't even talk to Docker"
Two errors stop you before you start, and they look alike but mean different things.
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock. The daemon is running; your user can't open the socket. Confirm with ls -l /var/run/docker.sock (owner root, group docker, mode srw-rw----) and id (no docker group). Fix: sudo usermod -aG docker $USER, then newgrp docker or log back in. The security catch, and the rootless alternative, are in Docker permission denied.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Either nothing is listening or you're pointed somewhere else. Docker's troubleshooting page names exactly those two causes. Check both:
$ sudo systemctl is-active docker # "inactive" or "failed" = daemon is down
$ env | grep DOCKER_HOST # set to a dead host or socket?
$ docker context ls # which endpoint the CLI is using
$ sudo journalctl -xu docker.service -n 50 # why the daemon refused to start
If the daemon is down, sudo systemctl start docker. If DOCKER_HOST points at a stale socket, unset DOCKER_HOST and remove it from ~/.bashrc or ~/.profile. If the journal shows the following directives are specified both as a flag and in the configuration file, a setting lives in both /etc/docker/daemon.json and the unit's ExecStart flags; remove one copy. Full walkthrough: cannot connect to the Docker daemon.
Bucket 2: "The container won't stay up"
Docker's run reference reserves three exit codes: 125 means the error is with the daemon itself (for example flag provided but not defined), 126 means the command can't be invoked, and 127 means it can't be found. Every other code is your process's own.
- Container exits immediately,
Exited (0): PID 1 finished or forked into the background. A container lives exactly as long as its main process. nginx needsdaemon off;, Apache needs-D FOREGROUND. Walked through in container exits immediately. Exited (127)withexec: "app": executable file not found in $PATH: typo inCMD, or the binary isn't in the image. Rundocker run -it --entrypoint sh <image>and look.Exited (137): 128 + 9, a SIGKILL. Ifdocker inspectshowsOOMKilled=true, the container hit its memory limit; raise--memoryor fix the leak. Covered in Docker exit code 137, with the Kubernetes version in OOMKilled.exec /usr/local/bin/app: exec format error: the image was built for another CPU architecture, typically arm64 on an amd64 host or the reverse. Comparedocker image inspect --format '{{.Architecture}}' <image>withuname -m. Fixed in Docker exec format error, and prevented for good with multi-arch builds using buildx.
Bucket 3: "It won't build or bind"
Bind for 0.0.0.0:8080 failed: port is already allocated. Another container or a host process holds the port. Find it with docker ps --filter publish=8080 and, for host processes, sudo ss -ltnp 'sport = :8080'. Stop it or publish on another port (-p 8081:8080). Details in port already allocated.
no space left on device. Images, stopped containers, volumes, and build cache filled the disk. See where it went before deleting anything:
$ docker system df # TYPE, TOTAL, ACTIVE, SIZE, RECLAIMABLE per category
$ docker builder prune # build cache, usually the biggest win
$ docker image prune -a # images not used by any container
Leave docker system prune --volumes for when you know no volume holds data you need. Reclaimed in no space left on device.
Builds that redo everything, or serve stale layers. Usually an early COPY . . that invalidates every later layer, or a missing .dockerignore that sends node_modules and .git as build context. Fixed in Docker build cache; a tight .dockerignore prevents half of it.
DNS failures inside builds or containers (Temporary failure in name resolution). The daemon warns Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it on hosts running dnsmasq or a resolver stub. Set explicit servers, then restart the daemon and test with docker pull hello-world:
# /etc/docker/daemon.json
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
Strip the comment line before saving: JSON has no comments, and a malformed daemon.json stops the daemon from starting, which sends you straight back to Bucket 1.
Bucket 4: Compose wiring
Compose errors are rarely Docker errors. The common three: variables that don't interpolate because the .env file isn't next to the compose file, depends_on that only waits for a container to start, not to be ready (use condition: service_healthy with a healthcheck), and network or container name clashes between projects. Covered in docker-compose errors.
Where this breaks
The bucket model assumes a local Docker Engine. Rootless daemons, Podman's Docker-compatible socket, and remote contexts over SSH change the socket path, so docker context ls comes before anything in Bucket 1. On Kubernetes nodes running containerd, there is no dockerd at all; use crictl and kubectl describe pod instead. And exit codes only help when PID 1 is your app: a shell wrapper that swallows the child's status reports 0 or 1 no matter what actually failed.
The mental model
Name the bucket from docker ps -a plus the exit code, and a cryptic message becomes a short checklist. Once the basics are solid, slim the image down with distroless base images so there's less inside it to go wrong.
Questions people ask
How do I troubleshoot a Docker container that keeps failing?
Run docker ps -a to get the exit code, then docker logs --tail 50 <container> for the last output. Code 0 means the main process finished, 127 means a missing command, 137 means it was killed (check OOMKilled). If the logs are empty, start a shell in the image with docker run -it --entrypoint sh <image> and run the command by hand.
What does "Cannot connect to the Docker daemon" mean?
The CLI found no daemon at the address it tried. Either dockerd isn't running (sudo systemctl is-active docker, then sudo systemctl start docker) or DOCKER_HOST or the active context points at a socket that no longer exists. It is different from "permission denied", where the daemon is running but your user isn't allowed to open the socket.
How do I fix "docker daemon not running" on WSL?
With Docker Desktop, the daemon runs inside Desktop, so start the app and enable WSL integration for your distro in its settings. With Docker Engine installed directly in the distro, start it yourself: sudo systemctl start docker if systemd is enabled in WSL, otherwise sudo service docker start. Then confirm with docker info.
The call we'd make
Read the exit code and the last log lines before anything else; as of October 2026 that still answers most Docker failures in under a minute. Learn the four buckets so a new error slots into one before you start guessing, and use each linked guide as the fast path for its failure. The same dozen errors follow you across every project, and turning each into a reflex is what separates a five-minute fix from a lost afternoon.
Sources
Cite this article
Kiril Urbonas (2026). Docker Error Troubleshooting: The Complete Guide. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/docker-error-troubleshooting-guide
[Docker Error Troubleshooting: The Complete Guide](https://www.devopsness.com/blog/docker-error-troubleshooting-guide) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.