Docker Build and Runtime Debugging Cheatsheet

Fast commands and triage flow for broken Docker builds, startup crashes, and container networking issues.

2 min read
#devops #reliability

Use this as a rapid troubleshooting guide when Docker builds fail, containers crash on startup, or ports are unreachable, so you can systematically isolate the root cause, reduce downtime, and recover service behavior with minimal guesswork instead of thrashing through random rebuilds and shell sessions.

Build Fails Quickly

@itsnas
main
# Show complete build logs (including intermediate stages)
docker build --progress=plain -t app:debug .
 
# Rebuild without cache to validate stale-layer issues
docker build --no-cache -t app:fresh .
main
Naseebullah
Ln 1, Col 1UTF-8

Container Exits Immediately

@itsnas
main
# See last logs with timestamps
docker logs --timestamps --tail=200 <container>
 
# Start shell in image to verify files and entrypoint
docker run --rm -it --entrypoint sh app:debug
main
Naseebullah
Ln 1, Col 1UTF-8

Port Not Reachable

  1. Confirm container is listening on expected port.
  2. Confirm host mapping exists (-p host:container).
  3. Confirm service binds to 0.0.0.0, not 127.0.0.1.
@itsnas
main
docker ps --format "table {{.Names}}\t{{.Ports}}"
main
Naseebullah
Ln 1, Col 1UTF-8

Five Minute Triage Checklist

  • Did dependencies install in the same stage where they are used?
  • Is the runtime image missing shell/system libs?
  • Is NODE_ENV=production hiding required dev tooling?
  • Are secrets injected at runtime, not build time?
  • Can issue be reproduced locally with same image digest?

Copyright © 2025-present itsnas.me 
All Rights Reserved.