Why Do My Docker Containers Exit? Understanding Common Exit Codes
This article explains why Docker containers stop running by detailing how to view exit codes, describing the most common exit codes such as 0, 1, 137, 139, and 143, and clarifying the actions that cause each code, helping developers troubleshoot container failures.
Why does a container stop running? Understanding Docker exit codes helps diagnose container failures. This article lists the most common exit codes and explains the actions that cause them.
How to view exit codes
Method 1: Inspect the pod’s container exit code $ kubectl describe pod xxx Method 2: Use Docker
$ docker ps --filter "status=exited"
$ docker inspect <container-id> --format '{{.State.ExitCode}}'Method 3: Manual output
$ docker container run alpine sh -c "exit 1"
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
61c688005b3a alpine "sh -c 'exit 1'" About a minute ago Exited (1) 3 seconds agoCommon exit codes
Exit Code 0
The container has no foreground process attached.
This code is an exception to other exit codes.
It does not necessarily indicate an error; it can be used to stop a container after its work is done.
Running docker run hello-world shows “Hello from Docker!” and the container appears with status code 0.
Exit Code 1
Program error or missing file referenced in Dockerfile (e.g., wrong entrypoint).
Errors can be simple like division by zero or complex such as null reference crashes.
Exit Code 137
Container received SIGKILL (kill -9).
Triggered by docker kill from user or daemon.
Often occurs when pod resource limits are low, causing OOMKilled; the state shows "OOMKilled": true and dmesg logs OOM.
Exit Code 139
Container received SIGSEGV (kill -11), indicating an invalid memory reference.
Usually caused by code issues or problems in the base image.
Exit Code 143
Container received SIGTERM (kill -15), typically from docker stop.
Sometimes docker stop leads to Exit Code 137 if the process cannot handle SIGTERM and Docker escalates to SIGKILL after a timeout.
Less common exit 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 exit codes; many programs use exit(1) or exit(-1) which maps to 255.
Exit code ranges
Valid range is 0‑255; 0 means normal exit.
External interruptions produce codes 129‑255.
Program‑initiated abnormal exits are usually 1‑128.
If a negative code is specified, it is converted using 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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
