Docker Logs, Debugging and Troubleshooting Guide
Docker troubleshooting becomes easier when you follow a clear flow: check container status, read logs, inspect configuration, verify ports, test networks, and review volumes.
Quick troubleshooting flow
- Check if the container is running.
- Read logs.
- Check exit code.
- Inspect ports, mounts, and environment variables.
- Exec into the container if it is running.
- Test network connectivity.
- Rebuild image if needed.
Check container status
docker ps docker ps -a
Read logs
docker logs CONTAINER_NAME docker logs -f CONTAINER_NAME docker logs --tail 100 CONTAINER_NAME
Inspect container details
docker inspect CONTAINER_NAME
Inspect output can show environment variables, mounts, ports, network settings, image ID, restart policy, and exit code.
Exec inside a running container
docker exec -it CONTAINER_NAME sh docker exec -it CONTAINER_NAME bash
Common issue: container exits immediately
Usually the main process finished or failed. Check logs and exit code.
docker ps -a docker logs CONTAINER_NAME
Common issue: port not working
docker run -d -p 8080:80 nginx docker port CONTAINER_NAME
Check whether the app listens on the correct container port and whether the host port is already used.
Common issue: container cannot reach database
- Check if both containers are on the same network.
- Use service/container name instead of localhost.
- Check database startup readiness.
- Check credentials and environment variables.
Network debug commands
docker network ls docker network inspect NETWORK_NAME docker exec -it app sh ping db nslookup db
Volume debug commands
docker volume ls docker volume inspect VOLUME_NAME docker inspect CONTAINER_NAME | grep Mounts -A 20
Common mistakes
- Debugging randomly without reading logs.
- Using localhost inside one container to reach another container.
- Forgetting port publishing.
- Deleting containers before checking logs.
- Removing volumes during cleanup and losing data.
Best practices
- Always start with docker ps -a and logs.
- Name containers and services clearly.
- Use health checks for important apps.
- Keep Dockerfiles simple and reproducible.
- Document common fixes for your team.
Related Melochip guides
- Docker Learning Path
- Docker Commands Explained
- GitLab CI/CD Troubleshooting Guide
Official references
- docker logs reference
- docker inspect reference
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Prepare for Docker interviews with practical questions and real-time scenarios covering images, containers, Do...
2 min read · Sep 17, 2026
Learn Docker environment variables and secrets, including docker run -e, env files, Compose environment, secre...
2 min read · Sep 17, 2026
Learn Docker security best practices for images, containers, users, secrets, registries, scanning, least privi...
2 min read · Sep 17, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.