Find out why a container exited
Read-only
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Reads a stopped container's exit code, out-of-memory flag, and final log lines to diagnose why it stopped, without restarting or modifying it.
dockerdebugcrashexit-code
Parameters
Name or ID of the exited container to diagnose.
Commands
Confirm the container's status and when it exited
docker ps --all --filter name=<container>Read State.ExitCode, State.OOMKilled, and State.Error from the JSON output
docker inspect <container>Show the final log lines leading up to the exit
docker logs --tail 50 <container>Verification
docker inspect <container>The State section shows the exit code; 0 is a clean exit, 137 often means killed (OOM or docker stop), and 1 or higher is an application error.
Undo
Not undoable
This recipe only reads state and logs and changes nothing.
Pitfalls
- Exit code 137 is SIGKILL; check State.OOMKilled to distinguish out-of-memory kills from manual stops.
- Exit codes above 128 encode a signal number (128 + signal), such as 143 for SIGTERM.
- If the container was started with --rm it was deleted on exit and cannot be inspected.