Find your exact problem and fix it โ each section follows Problem โ Symptoms โ Diagnose โ Fix.
These 5 commands give you the full picture within 60 seconds and resolve most issues without deeper investigation.
docker ps -a
Check STATUS โ Exited (1) = crash ยท Exited (0) = ran and finished ยท Restarting = crash-loop.
docker logs <container> --tail 100
The error is almost always in the last 10 lines. Pipe to grep -i error if output is large.
docker inspect --format '{{.State.OOMKilled}}' <container>If true โ increase memory limit. OOM kills leave no app-level log.
docker stats --no-stream
CPU pegged at 100 % = throttled. MEM near limit = impending OOM. BLOCK I/O high = disk bottleneck.
docker events --since 30m
Shows OOM kills, restarts, and daemon signals invisible in container logs.
| Exit Code | Meaning | Go To |
|---|---|---|
| 0 | Clean finish โ process ran and exited normally | Container Won't Stay Up tab |
| 1 | App crash / unhandled exception | docker logs for stack trace |
| 127 | Binary not found in image | Build Errors tab |
| 137 | OOM kill (SIGKILL) | Crashes & OOM tab |
| 139 | Segfault (SIGSEGV) | App bug โ check binary |
| 143 | Graceful shutdown (SIGTERM) | Check restart policy |
Exited (127) โ command not foundexec: "mybin": executable file not found in $PATH or exit code 127.docker logs <container> --tail 20 # Verify binary exists in image docker run --rm --entrypoint sh myimage -c "which mybin && mybin --version"
Add the package to your Dockerfile.
RUN apt-get update && apt-get install -y mypackage
Use the absolute path or verify the binary name.
CMD ["/usr/local/bin/mybin", "--flag"]
KeyError: 'DB_URL' / undefined environment variable / connection refused on startup.docker inspect <container> | grep -A30 '"Env"' docker logs <container> --tail 30
docker run -e DB_URL=postgres://host:5432/db myimage # or via env file docker run --env-file .env myimage
Make the app fall back to a sane default so startup isn't fatal.
Bind for 0.0.0.0:8080 failed: port is already allocatedss -tlnp | grep :8080 docker ps --filter publish=8080
docker run -p 8081:8080 myimage
docker stop $(docker ps -q --filter publish=8080)
lsof -ti:8080 | xargs kill -9
Unable to find image 'myimage:tag' locally or manifest unknowndocker images | grep myimage docker pull myimage:tag # try pulling explicitly
docker build -t myimage:tag .
docker search myimage docker pull myimage:latest
docker logs <container> # any output at all?
docker inspect --format '{{.Config.Cmd}}' <container># BAD โ daemon exits after forking CMD ["nginx"] # GOOD โ blocks the process CMD ["nginx", "-g", "daemon off;"]
If CMD runs a script that exits, the container stops. Use --restart=on-failure for retry, or run interactively for debugging.
docker run -it --entrypoint /bin/sh myimage
docker ps shows Restarting (1) X seconds ago. Restart count keeps climbing.docker logs --tail 40 <container>
docker inspect --format '{{.RestartCount}}' <container>
docker inspect --format '{{.State.ExitCode}}' <container>docker update --restart=no <container> docker stop <container> docker logs <container>
docker run --restart=on-failure:3 myimage # stops retrying after 3 crashes
docker run --restart=no -it myimage
docker inspect --format '{{.State.OOMKilled}}' <container>
# โ true confirms OOM
dmesg | grep -i "oom\|killed" # host kernel log
docker stats --no-stream <container>docker run -m 2g --memory-swap 2g myimage # compose.yml: mem_limit: 2g
docker exec -it <container> sh -c "free -m" docker stats <container> # watch MEM USAGE live
If usage grows unbounded, the app is leaking. Profile in staging before increasing limits blindly.
docker stats shows CPU near 100 %. App responds but sluggishly.docker stats --no-stream <container> docker exec -it <container> sh -c "top -bn1 | head -20" docker exec -it <container> sh -c "ps aux --sort=-%cpu | head"
docker run --cpus="2.0" myimage # was 0.5? docker update --cpus="2.0" <running-container>
Heavy writes to the overlay2 layer are slow. Move I/O-heavy paths to a volume.
docker run -v mydata:/app/data myimage
docker system df docker system prune -af
curl: (6) Could not resolve host or connect: network is unreachable inside container.docker exec -it <container> ping -c3 8.8.8.8 # IP reachable? docker exec -it <container> nslookup google.com # DNS working? docker exec -it <container> curl -v https://example.com
# Missing nat rule โ restart Docker to restore sudo systemctl restart docker # Verify rule exists sudo iptables -t nat -L POSTROUTING -n | grep MASQUERADE
# One-off
docker run --dns 8.8.8.8 myimage
# Permanent โ /etc/docker/daemon.json
{"dns": ["8.8.8.8", "1.1.1.1"]}
sudo systemctl reload dockerdocker run \ -e HTTP_PROXY=http://proxy:3128 \ -e HTTPS_PROXY=http://proxy:3128 \ -e NO_PROXY=localhost,127.0.0.1 \ myimage
Could not resolve host: db or connection refused when using container name as hostname.docker inspect <container-a> | grep -A10 '"Networks"' # Are both containers on the same user-defined network? docker network ls docker network inspect <network> # who's attached?
docker network create mynet docker run -d --name db --network mynet postgres:15 docker run -d --name app --network mynet myapp # Now: app โ ping db โ
docker network connect mynet <container>
localhost to reach another container. Each container has its own network namespace โ use the container name instead.curl localhost:8080 hangs or returns Connection refused even though the container is running.docker port <container> # what's actually mapped? docker exec -it <container> ss -tlnp # what is the app binding to?
Port mapping only works if the app listens on all interfaces inside the container.
# BAD in your app config:
listen("127.0.0.1", 3000)
# GOOD:
listen("0.0.0.0", 3000)docker run -p 8080:80 myimage # host:container # Check mapping: docker port <container>
apt-get install fails โ package not foundE: Unable to locate package xyz during docker build.docker build --progress=plain . # show full output docker build --no-cache . # stale cache?
RUN apt-get update && apt-get install -y \
curl git vim \
&& rm -rf /var/lib/apt/lists/*docker build --no-cache -t myimage .
COPY fails โ file not found in build contextCOPY failed: file not found in build context: "src/app.py"ls -la src/app.py # does it exist? cat .dockerignore # could it be excluded? docker build --progress=plain . 2>&1 | head -20
# Run from the project root, not a subdirectory docker build -t myimage . # or specify context explicitly docker build -f docker/Dockerfile -t myimage .
Open .dockerignore and remove or narrow the pattern that's blocking the file.
docker images shows image size > 1 GB. docker push is extremely slow.docker history myimage # which layer is bloated? docker system df # overall disk usage
FROM python:3.11-slim # not python:3.11 FROM node:20-alpine # not node:20
FROM golang:1.22 AS builder COPY . . && RUN go build -o app FROM scratch COPY --from=builder /app/app /app ENTRYPOINT ["/app"]
RUN apt-get install -y build-essential \ && make install \ && apt-get purge -y build-essential \ && rm -rf /var/lib/apt/lists/*
npm install / pip install even though dependencies didn't change.COPY . . # all files first RUN npm install # cache busted on any code change
COPY package*.json ./ # deps manifest first RUN npm ci # cached until deps change COPY . . # code copied last
docker rm and docker run. Files written inside the container are gone.docker inspect <container> | grep -A20 '"Mounts"' # Empty Mounts = no volume โ data is in the ephemeral layer
docker run -v pg_data:/var/lib/postgresql/data postgres:15 # Data survives docker rm; lost only on docker volume rm
docker run -v /host/uploads:/app/uploads myimage # Data lives in /host/uploads on the host
Permission denied when app tries to write to /data or any bind-mounted directory.docker exec -it <container> ls -lan /data # note UID:GID
docker inspect --format '{{.Config.User}}' <container># Container runs as UID 1000: sudo chown -R 1000:1000 /host/data docker run -v /host/data:/data myimage
RUN mkdir -p /data && \
chown -R appuser:appuser /data
USER appuserdocker run -v /host/data:/data:z myimage
docker inspect <container> | grep -A5 '"Source"' # Verify the host path is correct and populated ls -la /host/path
# BAD โ relative path silently creates wrong dir docker run -v data:/app/data myimage # โ named volume, not ./data! # GOOD docker run -v /absolute/host/path:/app/data myimage
Docker creates the host directory if it doesn't exist โ but empty. Pre-create and populate it before running.
systemctl start docker failsJob for docker.service failed or all docker commands return Cannot connect to the Docker daemon.sudo systemctl status docker sudo journalctl -u docker -n 80 --no-pager # last 80 lines of daemon log
python3 -m json.tool /etc/docker/daemon.json # Fix syntax errors, then: sudo systemctl restart docker
sudo rm -f /var/run/docker.pid sudo rm -f /var/run/docker.sock sudo systemctl start docker
sudo journalctl -u docker | grep "storage-driver"
# daemon.json โ explicitly set overlay2
{"storage-driver": "overlay2"}permission denied connecting to Docker socketpermission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockls -la /var/run/docker.sock # check ownership id # are you in the docker group? groups $USER
sudo usermod -aG docker $USER newgrp docker # apply now, without logout
sudo chmod 666 /var/run/docker.sock
docker group grants root-equivalent access. Only add trusted users in production.docker logs returns nothingdocker logs <container> returns empty output even though the container is running and the app is logging.docker inspect --format='{{.HostConfig.LogConfig.Type}}' <container>
# If not "json-file" โ docker logs won't workIf using journald, awslogs, etc., use the driver's native tool.
journalctl CONTAINER_NAME=<name> -n 100
Docker only captures stdout/stderr. Configure your app to log to stdout, or tail the log file inside the container.
docker exec -it <container> tail -f /var/log/app.log
# daemon.json โ set retention
{
"log-driver": "json-file",
"log-opts": {"max-size": "100m", "max-file": "3"}
}no space left on device โ Docker disk is fullno space left on device on build, pull, or container write operations.docker system df # breakdown by type docker system df -v # per-image / per-volume detail df -h /var/lib/docker # host disk usage
docker container prune # step 1 โ stopped containers docker image prune # step 2 โ dangling images docker image prune -a # step 3 โ ALL unused images docker volume prune # step 4 โ unused volumes docker builder prune # step 5 โ build cache docker system prune -af --volumes # โข๏ธ nuclear โ everything unused
docker system prune -af --volumes permanently deletes all unused images and volumes. Run docker system df first to understand impact.