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.

CodeMeaningUsually
0Exited normallyThe command finished, or the app shut down cleanly
1Application errorAn unhandled exception, a failed startup check, a bad config
2Misuse of a shell commandA bad argument or syntax error in an entrypoint script
125Docker couldn't run the containerAn invalid docker run flag, or a daemon error
126Command can't be executedThe entrypoint isn't executable, or is for another CPU architecture
127Command not foundA typo, or a binary missing from the image
130Interrupted (SIGINT, 128+2)Ctrl-C in an attached terminal
137Killed (SIGKILL, 128+9)Out of memory, or docker stop after its timeout
139Segmentation fault (SIGSEGV, 128+11)A crash in native code, or an image built for another platform
143Terminated (SIGTERM, 128+15)docker stop, docker compose down, or the orchestrator stopping it

First, three commands

bash
# 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=myapp

Exit 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:

bash
docker run --rm -it --entrypoint sh myimage
# then start the app by hand and watch it fail

Exit 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/sh on 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 has curl, bash or 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:

bash
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, or deploy.resources.limits.memory in Compose), tell the runtime about it (-Xmx for Java, --max-old-space-size for 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"]), exec in 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

0, 143 and 130 are stops someone asked for. 137 is one too, unless OOMKilled is true. Anything else is the container failing on its own. That's how Spot Downtime decides whether a stopped container is worth an alert.

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.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading