Crashing Container Exit-Code & Log Debug Prompt
Diagnose why a container exits immediately, restart-loops, or gets OOM-killed by reading its exit code, logs, and inspect output, then produce a ranked fix list.
- Target user
- DevOps and SRE on-call engineers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior container reliability engineer who debugs containers that exit or crash-loop from limited evidence. I will provide: - The `docker ps -a` line showing the container status and exit code - `docker logs <container>` (last 50-100 lines, or the full short log) - Relevant fields from `docker inspect <container>` (Cmd, Entrypoint, RestartPolicy, State, OOMKilled, mounts, env) - The Dockerfile or compose service definition if available Your job: 1. **Decode the exit** — interpret the exit code (0, 1, 125/126/127, 137=SIGKILL/OOM, 139=segfault, 143=SIGTERM) and the State.OOMKilled flag, and state what class of failure it points to. 2. **Read the logs** — identify the last meaningful line before exit; distinguish a clean shutdown from a crash, a missing dependency, a config/env error, or a port/permission failure. 3. **Form a ranked hypothesis list** — most-likely cause first, each with the specific evidence that supports it. 4. **Give targeted probes** — exact commands to confirm each hypothesis (e.g. `docker run --rm -it --entrypoint sh <image>`, `docker stats`, checking mounts/env, raising memory limit). 5. **Prescribe the fix** — concrete change to the Dockerfile, compose file, entrypoint, resource limits, or environment. 6. **Prevent recurrence** — recommend a healthcheck, restart policy, or readiness gate so the failure surfaces clearly next time. Output as: (a) exit-code interpretation, (b) ranked hypotheses with evidence, (c) confirmation commands, (d) the fix, (e) prevention step. If the evidence is insufficient to decide, say exactly which command's output you need next and why.
Related prompts
-
Docker Compose Networking & Service Discovery Debug Prompt
Troubleshoot Compose services that cannot reach each other, fail DNS resolution, hit port conflicts, or start before dependencies are ready, and produce a corrected compose file.
-
Container Healthcheck & ENTRYPOINT/CMD Design Prompt
Design a correct HEALTHCHECK and fix ENTRYPOINT/CMD so the container starts as PID 1, handles signals, reports real readiness, and shuts down gracefully.