Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Docker container exits with code 137

ErrorExited (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.

  • Applies to Docker Engine 28, Docker Compose 2, Linux
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-container
  2. 2Match what you see, then jump to its fix

    1. 1OOMKilled is true in the inspect outputThe container ran out of memoryFix
    2. 2OOMKilled is false and the exit happened during docker stop or compose downDocker stopped the container and had to force itFix
    3. 3OOMKilled is false and nobody stopped the containerSomething else sent SIGKILLFix

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-stream

2Fix

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-image

3Verify

Run the same workload again; the container stays up and OOMKilled stays false.

docker inspect --format '{{.State.OOMKilled}}' my-container

Confirmed by docs.docker.com

Did this fix it?

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-container

2Fix

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-image

3Verify

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-container

Confirmed by docs.docker.com

Did this fix it?

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-container

2Fix

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=kill

3Verify

After the sender is fixed, the container runs past the time it used to die.

docker ps --filter name=my-container

Confirmed by gnu.org

Did this fix it?

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

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.