D

Docker Troubleshooting

Diagnose containers that exit immediately, images that won't build, and networking failures.

Updated 2026-09-03

On this page

Container Exiting Immediately

A container that stops right after docker run almost always means its main process exited — Docker isn't hanging onto a container just because you didn't attach to it.

Check the exit code

docker ps -a

The STATUS column shows Exited (code) — code 0 means the process finished cleanly (often because there was nothing left to keep it running), non-zero means it errored.

Read the container's own logs

docker logs CONTAINER_ID

Shows whatever the process printed before exiting — usually the actual error.

Confirm the image has a real foreground process

A container exits as soon as its PID 1 process exits. An image whose CMD is something like a one-shot script, or a service that daemonizes itself into the background, will exit immediately even though "it looks fine" — PID 1 needs to be a long-running foreground process.

Build Failing

docker build --no-cache -t app .

Rules out a stale layer cache as the cause before debugging further.

docker build --progress=plain -t app .

Shows full, unbuffered output from every build step instead of Docker's collapsed default — needed to see the real error from a failing RUN command.

Common build failures

A COPY referencing a path that doesn't exist in the build context, a package manager command failing because a base image's package cache is stale (needs an update step before install), or a multi-stage build referencing a stage name that was renamed or removed.

Container Can't Reach the Network

docker exec CONTAINER_ID ping -c 3 8.8.8.8

Tests whether the container has outbound network connectivity at all.

docker network inspect bridge

Confirms the container is actually attached to the network you expect, and check its assigned IP.

Default bridge has no DNS between containers

Containers on Docker's default bridge network can't resolve each other by container name — only a user-defined network (docker network create) gives you that. A container that can ping an IP but not resolve another container's name is very likely still on the default bridge.

Port Already in Use

Error response from daemon: driver failed programming external connectivity:
Bind for 0.0.0.0:8080 failed: port is already allocated
lsof -i :8080

Finds whatever process (often another container, or a leftover from a previous run) already holds the port on the host.

docker ps --filter publish=8080

Checks specifically whether another container already published this host port.

Out of Disk Space

Docker's layer cache, unused images, and stopped containers accumulate quickly on a build host.

docker system df

Shows how much disk space images, containers, volumes and the build cache are each using.

docker system prune -a --volumes
destructive

Reclaims space by removing every unused image, stopped container, network and volume. Confirm nothing important lives only in an idle named volume first.