← All cheatsheets
Docker Troubleshooting Cheatsheet
Debug containers, inspect logs, trace networking issues, and fix common Docker problems.
What it is
This cheatsheet covers the most common Docker debugging workflows: inspecting logs, network tracing, container inspection, and disk management.
Quick start
Tail the last 100 log lines and follow.
Get full low-level JSON details.
Open a shell in a running container.
Debugging commands
| Scenario | Command | What it tells you |
|---|---|---|
| Container crashes | docker logs --tail 200 <ctr> |
Last N log lines before exit. |
| Container keeps restarting | docker inspect <ctr> | grep -A5 State |
Exit code, error, restart count. |
| Disk full | docker system df |
Space used by images, containers, volumes, cache. |
| Network issues | docker network inspect <net> |
Connected containers, IPs, DNS settings. |
| High CPU | docker stats |
Live CPU, memory, network I/O per container. |
| Port conflict | docker ps --filter publish=8080 |
Which container is using port 8080. |
| Image too large | docker history <image> |
Layer-by-layer size breakdown. |
Real-world examples
Debug why a container keeps restarting
# See last exit reason
docker inspect myapp --format '{{.State.ExitCode}} {{.State.Error}}'
# Read last 200 log lines
docker logs --tail 200 myapp
# Check restart policy
docker inspect myapp --format '{{.HostConfig.RestartPolicy}}'
Reclaim disk space
docker system df # See what's using space
docker image prune -af # Remove unused images
docker volume prune # Remove unused volumes
docker system prune -af --volumes # Nuclear option
Best practices
- Check
docker eventsfor a real-time stream of Docker daemon events. - Use
docker inspectliberally — it reveals everything about a container's config and state. - Always set a
--log-driverin production so logs persist after container removal.
Related cheatsheets
Last reviewed: 2026-06-15