Why Do My Docker Containers Exit? Decoding Common Exit Codes
This guide explains how to view Docker and Kubernetes container exit codes, lists the most common codes such as 0, 1, 137, 139, and 143, describes what each code means, and shows the commands and scenarios that generate them.
How to Check Container Exit Codes
There are three main ways to retrieve a container's exit code:
In Kubernetes, describe the pod: kubectl describe pod <pod-name> Using Docker, filter exited containers and inspect the state:
docker ps --filter "status=exited"
docker inspect <container-id> --format '{{.State.ExitCode}}'Run a container that deliberately exits and list it:
docker container run alpine sh -c "exit 1"
docker container ls -aCommon Exit Codes
Exit Code 0
The container finished without a foreground process.
It is considered a normal, successful termination.
Developers may use this code to signal that the container can stop automatically after completing its work.
Exit Code 1
General program error, such as a missing file referenced in the Dockerfile or an invalid entrypoint.
Can be caused by simple mistakes like division by zero or more complex crashes.
Exit Code 137
Indicates the container received a SIGKILL (kill -9).
Usually triggered by docker kill or by the Docker daemon when the pod exceeds its memory limit, resulting in an OOMKilled state.
Exit Code 139
Indicates a SIGSEGV (segmentation fault) caused by an invalid memory reference (kill -11).
Typically points to bugs in the application code or a corrupted base image.
Exit Code 143
Shows the container received a SIGTERM (kill -15), commonly from docker stop.
In some cases, docker stop may first send SIGTERM, wait ten seconds, then send SIGKILL, resulting in an exit code 137.
Less Common Codes
126 – Permission problem or non‑executable command.
127 – Command not found, often due to a typo in a shell script.
1 or 255 – Custom error codes; many programs use exit 1 or exit -1 (which maps to 255).
Exit Code Ranges
0–255 are valid; 0 means normal exit.
129–255 indicate termination by an external signal.
1–128 are typical program‑generated error codes.
Negative exit values are converted using the formula 256 – (|code| % 256).
References
http://tldp.org/LDP/abs/html/exitcodes.html
https://imroc.io/posts/kubernetes/analysis-exitcode/
https://medium.com/better-programming/understanding-docker-container-exit-codes-5ee79a1d58f6
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
