Skip to main content
Docker Error Troubleshooting: The Complete Guide

Docker Error Troubleshooting: The Complete Guide

KU
· Founder & Chief Editor
• 8 min read•Updated •80 views

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.

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:

Bash
$ 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 seeBucketFirst commandUsual fix
permission denied while trying to connect to the Docker daemon socketDaemon accessid, ls -l /var/run/docker.sockAdd user to docker group, re-login
Cannot connect to the Docker daemon at unix:///var/run/docker.sockDaemon accesssudo systemctl is-active dockerStart daemon, or unset DOCKER_HOST
Exited (0) seconds after startWon't stay updocker logsRun the main process in the foreground
Exited (127), executable file not found in $PATHWon't stay updocker run -it --entrypoint sh <image>Fix CMD or install the binary
Exited (137)Won't stay updocker inspect for OOMKilledRaise --memory or fix the leak
exec format errorWon't stay updocker image inspect architectureBuild for the host's platform
port is already allocatedBuild or binddocker ps --filter publish=8080Stop the holder or change the host port
no space left on deviceBuild or binddocker system dfPrune build cache and unused images
Temporary failure in name resolutionBuild or bindcat /etc/resolv.confSet "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:

Bash
$ 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 needs daemon off;, Apache needs -D FOREGROUND. Walked through in container exits immediately.
  • Exited (127) with exec: "app": executable file not found in $PATH: typo in CMD, or the binary isn't in the image. Run docker run -it --entrypoint sh <image> and look.
  • Exited (137): 128 + 9, a SIGKILL. If docker inspect shows OOMKilled=true, the container hit its memory limit; raise --memory or 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. Compare docker image inspect --format '{{.Architecture}}' <image> with uname -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:

Bash
$ 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:

JSON
# /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

Explore topics:DockerDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Docker Error Troubleshooting: The Complete Guide. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/docker-error-troubleshooting-guide

Markdown

[Docker Error Troubleshooting: The Complete Guide](https://www.devopsness.com/blog/docker-error-troubleshooting-guide) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.