⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 998+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Senior DevOps / SRE Docker Container Diagnostics Container Runbook

Q: What are the common reasons for containers continuously restarting, and what commands are used to list running vs all containers?

Master diagnostic guide for analyzing Docker container reboot loops, interpreting Linux process termination exit codes (0, 1, 127, 137, 143), and inspecting entrypoint failures.

#Docker #Linux #Containers #Exit Codes #Troubleshooting
🎙️ Candidate Opening & Architectural Context
"When a container with a restart policy (like restart: always) enters a reboot loop, it is because PID 1 terminated. The single most important diagnostic metric is the process Exit Code."
Advertisement

🛠️ Production Runbook & Step-by-Step Resolution

1

Inspect Running vs. All Containers and Exit Codes

docker ps only shows running containers. Use docker ps -a to see stopped, failed, and restarting containers with their exit status.

docker ps          # Lists only running containers
docker ps -a       # Lists all containers (including exited and crashing)
docker inspect <container-id> --format 'ExitCode: {{.State.ExitCode}}, Error: {{.State.Error}}'
2

Decoding Container Exit Codes

Exit Code 0: Process finished successfully (entrypoint completed without a foreground blocking process). Exit Code 1: Application threw an unhandled exception. Exit Code 127: Command or binary not found in PATH. Exit Code 137: Process received SIGKILL (128 + 9), caused by OOMKilled or host termination. Exit Code 143: Graceful SIGTERM (128 + 15).

3

Troubleshooting Entrypoint Foreground Processes

A Docker container only lives as long as its primary PID 1 process. If a startup script starts a daemon in the background (e.g., nginx &) and exits, PID 1 dies and the container stops immediately.

💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"docker ps -a reveals exited containers. Decode exit codes: 0 (backgrounded script exited), 1 (app crash), 127 (command not found), 137 (OOMKilled/SIGKILL)."
⚡ 60-Second Elevator Pitch Talking Points
  • Use docker ps -a to inspect all containers and extract the exact ExitCode.
  • Exit Code 0: entrypoint started a daemon in the background instead of foreground (no blocking PID 1).
  • Exit Code 137: 128 + 9 (SIGKILL), indicating the Linux kernel OOM killer terminated the process.
  • Exit Code 127: binary or shell interpreter specified in shebang (#!) was not found in image.
  • Inspect container startup with docker logs --tail 100 and docker inspect.
Advertisement
Want more Docker scenarios?
Explore our complete collection of scenario-based Docker interview runbooks.
Browse All Docker Questions →

📚 Related Production Scenarios in Docker