Skip to content
Blog

Container Diagnostics: Reading Exit Codes and Troubleshooting Crash Reasons

Decode Linux process exit status codes (137, 139, 143, 126, 127) in Docker to quickly diagnose container crashes and OOM kills.

Published on • November 17, 2026

AI Assistant

When a Docker container unexpectedly stops or enters a crash loop (CrashLoopBackOff), the first diagnostic step is determining why the application inside terminated.

In Linux and Docker, every exiting process returns an 8-bit integer known as an Exit Code (ranging from 0 to 255). Understanding exit codes allows you to immediately distinguish between code syntax errors, missing binary dependencies, out-of-memory kernel kills, and graceful shutdowns.

In this guide, we will break down standard Docker exit codes, explain how to retrieve them, and provide troubleshooting strategies.


1. How to Check Container Exit Codes

To inspect the exit code of a stopped container, run docker ps -a or docker inspect:

# View STATUS column showing exit status
docker ps -a --filter "status=exited"

Output Example

CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                      NAMES
c1a2b3d4e5f6   node-app:1.0   "docker-entrypoint.s…"   10 minutes ago   Exited (137) 9 minutes ago  api-service

Inspecting Exit Code and OOM Kill State via docker inspect

docker inspect api-service --format 'ExitCode: {{.State.ExitCode}}, OOMKilled: {{.State.OOMKilled}}, Error: {{.State.Error}}'

2. Common Docker Exit Codes Reference

Exit CodeSignal / MeaningCommon Cause & Resolution
0Success / Normal ExitProcess completed work cleanly (e.g., batch job or script finished).
1General ErrorApplication exception, uncaught error, or invalid configuration. Check application logs.
2Misuse of Shell BuiltinsShell syntax error in CMD or ENTRYPOINT wrapper script.
125Docker Daemon Errordocker run command syntax error or daemon failure (e.g., invalid flag).
126Command Cannot ExecutePermission issue on entrypoint script (chmod +x missing) or bad arch binary.
127Command Not FoundExecutable file listed in CMD / ENTRYPOINT does not exist in container $PATH.
137SIGKILL (128 + 9)Process killed by OS kernel. Usually Out Of Memory (OOM) killer or docker kill.
139SIGSEGV (128 + 11)Segmentation fault. Invalid memory access in C/C++/Rust compiled binary.
143SIGTERM (128 + 15)Graceful termination signal sent by docker stop or system orchestrator.

3. Deep Dive into Critical Exit Codes

Exit Code 137: Out of Memory (OOM) Killer

When a container consumes more RAM than allowed by its memory limit (--memory), or exceeds total host physical RAM + swap, the Linux kernel’s OOM Killer intervenes and sends an uncatchable SIGKILL (Signal 9) to PID 1.

  • Exit Code formula: 128 + 9 = 137.
  • Verification: Check OOMKilled boolean in docker inspect or check host kernel logs:
# Check kernel dmesg for OOM events
dmesg -T | grep -i oom
  • Solution: Increase container memory allocation (--memory="2g") or optimize application memory consumption.

Exit Code 127: Command Not Found

Occurs when the Dockerfile ENTRYPOINT or CMD specifies a script or binary that doesn’t exist at the given path.

  • Common Cause: Writing #!/bin/bash in a script built on an Alpine Linux base image (which uses /bin/sh instead of /bin/bash).
  • Solution: Install bash in your Dockerfile (RUN apk add --no-cache bash) or update the shebang line to #!/bin/sh.

Exit Code 126: Permission Denied

Occurs when the entrypoint shell script exists, but lacks execute permissions (+x).

  • Solution: Add RUN chmod +x /entrypoint.sh to your Dockerfile prior to execution.

4. Troubleshooting Workflow for Crashing Containers

Follow this 4-step checklist whenever a container fails on startup:

  1. Check Exit Code: Run docker inspect <container> --format '{{.State.ExitCode}}'.
  2. Read Logs: Stream last stderr/stdout logs with docker logs --tail 100 <container>.
  3. Verify OOM State: Run docker inspect <container> --format '{{.State.OOMKilled}}'.
  4. Test Entrypoint Interactively: Override entrypoint to debug:
docker run --rm -it --entrypoint sh <image_name>

Summary

Exit codes provide immediate diagnostic insight into container crashes. Recognizing 137 as an OOM kill, 127 as a missing executable, and 126 as a permission error accelerates root-cause analysis in DevOps environments.

Takeaway: Combine exit code verification (ExitCode and OOMKilled from docker inspect) with docker logs to diagnose and fix container failures rapidly.

Sources