docker run exit codes 125, 126, 127 and 137: what each one means
Docker uses exit codes 125, 126 and 127 for its own failures and passes the container's code through otherwise. Read the code before you read the logs.
What you see
docker: Error response from daemon: Container command 'foo' not found or does not exist.docker: Error response from daemon: Container command '/etc' could not be invoked.flag provided but not defined: --foo- A container with exit code
137
What it means
The exit code from docker run tells you where the failure happened. Per the Docker docs: 125 means the error is with the Docker daemon itself, 126 means the contained command can't be invoked, and 127 means the contained command can't be found. Any other code is the exit code of the command inside the container.
Codes above 128 follow the Unix convention of 128 plus a signal number. 137 is 128 + 9, SIGKILL, and 143 is 128 + 15, SIGTERM. That convention comes from the general Unix model, not the Docker docs, so confirm with the OOM flag below before you blame memory.
How to confirm the cause
- 1Read the code and the OOM flag together
docker inspect --format '{{.State.ExitCode}} oom={{.State.OOMKilled}}' CONTAINERoom=truewith 137 means the kernel killed it for memory. 137 withoom=falseusually means someone or something sent SIGKILL, for exampledocker killor a stop that timed out. - 2Read the first error in the logs
docker logs --tail 50 CONTAINER
Read the first error, not the last. Later lines are often fallout.
- 3For 126 and 127, check the command and the image contents
docker run --rm --entrypoint sh IMAGE -c 'ls -l /path/to/command; which command'
Needs a shell in the image. For a minimal image, check the path in the Dockerfile
COPYandENTRYPOINTlines instead.
Causes and fixes
125: Docker itself failed
- HOW TO TELL
- The message is about a flag or the daemon, not your program. The docs' example is
flag provided but not defined: --foo. - ROOT CAUSE
- The
docker runcommand was malformed, or the daemon could not start the container at all. - FIX
- Fix the command line. Run
docker run --helpto check the option.
126: the command is not executable
- HOW TO TELL
Container command ... could not be invoked.- ROOT CAUSE
- The path exists but is not something the container can run: a directory, a file without the execute bit, or the wrong format for the platform.
- FIX
- Add execute permission when you copy the file, for example
RUN chmod +x /app/start.sh, and check the file is a script or binary for this platform.
127: the command is not found
- HOW TO TELL
Container command 'foo' not found or does not exist.- ROOT CAUSE
- The
CMDorENTRYPOINTnames a file that is not in the image, or is not onPATH. A badCOPYpath or a multi-stage build that forgot to copy the binary are common. - FIX
- Check the Dockerfile
COPYpaths and the command, then rebuild. Use the absolute path to be sure.
137: killed by SIGKILL
- HOW TO TELL
- Exit code 137 and
oom=true, oroom=falseafter a stop. - ROOT CAUSE
- With
oom=true, the container hit its memory limit and the kernel OOM killer ended it. Withoom=false,docker stopsent SIGTERM, waited out the grace period, then sent SIGKILL because the app did not exit in time. - FIX
- For OOM, raise
--memoryor fix the leak. For a slow stop, make the app handle SIGTERM and exit promptly.
How to stop it coming back
- Test the container's entrypoint in CI with the exact command you deploy.
- Handle SIGTERM in the app so stops are clean.
- Set a memory limit and alert on OOM kills.
Keep going
- Runbook: Container keeps restarting: restart policy loop
- Runbook: Process killed by the out-of-memory killer
- Cheat sheet: Docker
- Lesson: the containers topic in Learn
Sources
- Docker docs: docker run, exit status
- Docker docs: Resource constraints, OOM
- OneUptime blog: interpreting Docker exit codes (for 137 and 143)
Docker documentation (docs.docker.com), read 18 Nov 2026 from the official docs repository.