Docker exit codes explained: 0, 1, 125, 126, 127, 137, 139 and 143
What each Docker container exit code means, how to tell a crash from a clean stop, why 137 is either out of memory or docker stop, and the commands that show what happened.
· 6 min read · By the Spot Downtime team
When a container stops, Docker keeps the exit code of its main process. docker ps -a shows it as Exited (137) 2 minutes ago, and it's the fastest clue to what happened. Codes from 0 to 125 come from your application or Docker itself; codes above 128 mean the process was killed by a signal, and the signal is the code minus 128.
| Code | Meaning | Usually |
|---|---|---|
0 | Exited normally | The command finished, or the app shut down cleanly |
1 | Application error | An unhandled exception, a failed startup check, a bad config |
2 | Misuse of a shell command | A bad argument or syntax error in an entrypoint script |
125 | Docker couldn't run the container | An invalid docker run flag, or a daemon error |
126 | Command can't be executed | The entrypoint isn't executable, or is for another CPU architecture |
127 | Command not found | A typo, or a binary missing from the image |
130 | Interrupted (SIGINT, 128+2) | Ctrl-C in an attached terminal |
137 | Killed (SIGKILL, 128+9) | Out of memory, or docker stop after its timeout |
139 | Segmentation fault (SIGSEGV, 128+11) | A crash in native code, or an image built for another platform |
143 | Terminated (SIGTERM, 128+15) | docker stop, docker compose down, or the orchestrator stopping it |
First, three commands
# The exit code, whether the kernel killed it for memory, and when
docker inspect --format '{{.State.ExitCode}} oom={{.State.OOMKilled}} {{.State.FinishedAt}}' myapp
# The last lines it wrote before dying
docker logs --tail 100 myapp
# Docker's own record of what happened to it
docker events --since 1h --filter container=myappExit code 0: it finished
Zero means success. For a job, migration or one-off task, that's expected. For a web server or worker, it means the main process returned when it should have kept running: often a process that forks into the background (like nginx without daemon off;, or a service started with & in a script), so the container's main process has nothing left to do. Run the service in the foreground.
Exit code 1: the application failed
A generic error from your app. The answer is almost always in the last lines of docker logs: a stack trace, a missing environment variable, a database it couldn't reach at startup. If the logs are empty, the app may log to a file inside the container; run it with an interactive shell to see:
docker run --rm -it --entrypoint sh myimage
# then start the app by hand and watch it failExit codes 125, 126, 127: it never started
- 125: Docker refused the run itself. The error is printed by
docker run, not in the container's logs: an unknown flag, a port already in use, a volume path that doesn't exist. - 126: the entrypoint exists but can't run. Add
RUN chmod +x /entrypoint.sh, check the script's first line points to a shell the image has (#!/bin/shon Alpine, which has no bash), and that Windows line endings didn't sneak in. - 127: the command isn't in the image or not on its
PATH. Common after switching to a slim or distroless base image that no longer hascurl,bashor your tool.
Exit code 137: out of memory, or stopped the hard way
137 means SIGKILL, which comes from one of two places. Check which:
docker inspect --format '{{.State.OOMKilled}}' myapp- true: the kernel killed it for going over its memory limit (or the host ran out). Raise the limit (
--memory 1g, ordeploy.resources.limits.memoryin Compose), tell the runtime about it (-Xmxfor Java,--max-old-space-sizefor Node.js), or find the leak. Our guide to out-of-memory kills covers the host side. - false: something sent SIGKILL. Usually
docker stop: it sends SIGTERM, waits 10 seconds, then kills. If your app takes longer to shut down, or ignores SIGTERM because a shell script is PID 1 and doesn't pass signals on, it gets 137 on every deploy. Use the exec form (CMD ["node", "server.js"]),execin entrypoint scripts, or--init.
Exit code 139: a crash in native code
A segmentation fault. In application code it's usually a native library: an image processing or database driver built against a different C library (glibc vs Alpine's musl is the classic). It's also what you can see when an amd64 image runs on an arm64 host under emulation, or the other way round: check docker image inspect --format '{{.Architecture}}' myimage.
Exit code 143: stopped politely
143 is SIGTERM, what docker stop, docker compose down and Kubernetes send to stop a container. It's normal during deploys and restarts. Many apps exit with 143 instead of 0 when they don't handle the signal explicitly; that's harmless.
A clean stop vs a crash
Catch it next time
Restart policies hide crashes
With restart: unless-stopped, a crashed container comes back in seconds. Good for uptime, but you may never learn it crashed until it does so in a loop. See containers that keep restarting.
Get told when it happens
Spot Downtime's server agent reports every container's state, exit code and restarts each minute. A container that exits with an error code, is killed for memory or keeps restarting alerts you with the exit code in the message, and a Docker container monitor gives an important one its own uptime history and text or call alerts. Set it up with the server agent, installed with --docker.
Get new guides by email
Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.
Keep reading
- Docker · Servers · TroubleshootingPermission denied on /var/run/docker.sock: the safe fix"Got permission denied while trying to connect to the Docker daemon socket" means your user can't use Docker's socket. How to fix it with the docker group, why chmod 666 is a bad idea, and what to do for monitoring agents, CI runners and WSL.November 5, 2026 · 5 min read
- Docker · Servers · TroubleshootingDocker container keeps restarting? How to find out whyA container stuck in "Restarting (1)" crashes as soon as it starts and Docker keeps bringing it back. How to read its logs between restarts, pause the loop to debug it, and fix the usual causes.November 5, 2026 · 6 min read