⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ 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) →
← Back to All Docker & Containers Interview Questions Scenario 106 of 159 in Docker & Containers
Senior DevOps / SRE Docker Container Diagnostics Container Runbook
🎯 Target Role / Context: Docker & Container Runtime Troubleshooting

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
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: 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.

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).

Advertisement
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.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Structuring Dockerfile instructions inefficiently by copying app source before package manifests when configuring Docker Containers Continuously Copying code before package manifests (package.json, go.mod, requirements.txt) invalidates the build cache on every commit, forcing slow full reinstalls.
  2. Neglecting the PID 1 process reap problem and omitting proper SIGTERM signal forwarding when configuring Docker Containers Continuously If an application runs as PID 1 without an init system (like tini), it fails to reap zombie child processes and ignores SIGTERM signals, causing unclean 10s timeouts.
  3. Assembling single-stage images containing compilers, build SDKs, and header files in production when configuring Docker Containers Continuously Single-stage builds bloat image size by gigabytes and expose extensive package vulnerabilities; multi-stage builds isolate artifacts into minimal distroless images.
  4. Confusing container port forwarding on bridge networks with unisolated host networking mode when configuring Docker Containers Continuously Bridge networking utilizes iptables NAT translations which add latency overhead, whereas host networking bypasses the network namespace entirely.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →