A Docker container exits with code 137
Exited (137)Short answer
Exit code 137 is 128 plus signal 9, so the process was killed with SIGKILL. Two things send it: the kernel out-of-memory killer, or Docker forcing a stop after the grace period. Inspect the container state: OOMKilled true means memory; false means a forced stop or a kill from outside.
Fix it fast
1Find out which cause you have
Ask Docker whether the kernel killed the container for memory, and what exit code it recorded.
docker inspect --format '{{.State.OOMKilled}} {{.State.ExitCode}}' my-container2Match what you see, then jump to its fix
What does the error look like?
Exited (137)exited with code 137
Cause 1 of 3
The container ran out of memory
1Check
On Linux, when memory runs low the kernel kills processes, and by default it kills processes in a container that hits an out-of-memory error. The container state has an OOMKilled flag for this.
docker inspect --format '{{.State.OOMKilled}}' my-container
docker stats --no-stream2Fix
Give the container more memory with --memory, or reduce what the program uses. Do not turn the OOM killer off unless a memory limit is also set.
docker run -m 2g my-image3Verify
Run the same workload again; the container stays up and OOMKilled stays false.
docker inspect --format '{{.State.OOMKilled}}' my-containerConfirmed by docs.docker.com
Cause 2 of 3
Docker stopped the container and had to force it
1Check
docker stop sends SIGTERM and, after a grace period (10 seconds on Linux by default), forcibly kills with SIGKILL. A program that ignores SIGTERM ends up with 137.
docker inspect --format '{{.Config.StopSignal}}' my-container2Fix
Run an init process as PID 1 so signals are handled, and make the app exit on SIGTERM. If it needs longer to shut down, raise the stop timeout.
docker run --init --stop-timeout 30 my-image3Verify
Stop the container and read its exit code; it is 0 or the app's own code, not 137.
docker stop my-container
docker inspect --format '{{.State.ExitCode}}' my-containerConfirmed by docs.docker.com
Cause 3 of 3
Something else sent SIGKILL
1Check
Bash uses 128 plus the signal number for a command that dies on a fatal signal, so 137 means signal 9, whoever sent it: a monitoring tool, a CI job cancel, or a host script.
docker events --since 1h --filter container=my-container2Fix
Find the sender in the event log or the host's job scheduler and stop it from killing the container, or give it a proper graceful stop.
docker events --since 1h --filter event=kill3Verify
After the sender is fixed, the container runs past the time it used to die.
docker ps --filter name=my-containerConfirmed by gnu.org
How do I stop it coming back?
- Set a memory limit on every production container, so one service cannot starve the rest.
- Handle SIGTERM in the application and use --init for programs that spawn children.
- Alert on OOMKilled in monitoring rather than on exit codes alone.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A dev container port does not open in the browser when Docker runs on a remote host
If your application only accepts calls from localhost, it will reject connections from published ports
Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.
3 causes, each with a fix