Home › Docker

Container exited with code 137 (Docker) — how to fix

my-app-1 exited with code 137
CONTAINER ID   IMAGE    STATUS                       NAMES
3f2a1b9c8d7e   my-app   Exited (137) 2 minutes ago   my-app

Quick fix: Run docker inspect -f '{{.State.OOMKilled}}' <container>. If true, raise the memory limit (docker run -m 2g, deploy.resources.limits.memory in Compose, or Docker Desktop's memory setting) or reduce the app's memory use. If false and it happened on stop, make the app handle SIGTERM: use exec-form CMD ["node", "server.js"] or docker run --init.

What it means

When a process is killed by a signal, its exit code is 128 + the signal number. 137 = 128 + 9, and signal 9 is SIGKILL, which can't be caught or ignored. Two things normally send it:

  1. The kernel OOM killer, when the container hits its memory limit (or the host/VM runs out of memory).
  2. Docker itself, when docker stop / docker compose down sent SIGTERM and the process was still running after the grace period (10 seconds by default).

Find out which:

docker inspect -f '{{.State.OOMKilled}} {{.State.ExitCode}}' my-app

true 137 means out of memory. false 137 usually means it was killed after a stop request (or by someone running kill -9).

Related: exit code 143 = 128 + 15 (SIGTERM), meaning the process exited on the normal stop signal.

Cause 1: out of memory

The container has a memory limit (-m, Compose mem_limit / deploy.resources.limits.memory), or it has no limit but the host, or the Docker Desktop VM, has too little RAM.

Fix 1

Watch usage while it runs:

docker stats my-app

Raise the limit if the app legitimately needs more:

docker run -m 2g my-app
services:
  app:
    image: my-app
    deploy:
      resources:
        limits:
          memory: 2g

On Docker Desktop (macOS/Windows), all containers share one VM. Increase its memory in Settings, Resources. On WSL 2, memory is set in %UserProfile%\.wslconfig:

[wsl2]
memory=8GB

On a Linux host, the kernel log confirms an OOM kill:

sudo dmesg -T | grep -i -E "killed process|out of memory"

Also make the runtime respect the limit. Node's heap size isn't always derived from the container limit, so cap it below the limit (NODE_OPTIONS=--max-old-space-size=1536 for a 2 GB container). For Java, use a percentage-based heap such as -XX:MaxRAMPercentage=75.0.

Builds can hit this too: RUN npm run build exiting with 137 means the build step ran out of memory. Give Docker more memory or reduce build parallelism.

Cause 2: the app ignores SIGTERM

docker stop sends SIGTERM to PID 1 in the container. If PID 1 is a shell (shell-form CMD npm start runs /bin/sh -c), the signal often doesn't reach your app, nothing exits, and after 10 seconds Docker sends SIGKILL: exit 137 and a slow shutdown.

Fix 2

Use exec form so your process is PID 1 and receives the signal:

CMD ["node", "server.js"]

If you need a wrapper script, end it with exec so the app replaces the shell:

#!/bin/sh
# setup...
exec node server.js

Or add a tiny init process that forwards signals:

docker run --init my-app
services:
  app:
    init: true

And handle the signal in the app, e.g. in Node:

process.on('SIGTERM', () => server.close(() => process.exit(0)));

If shutdown genuinely needs longer, raise the grace period: docker stop -t 30 my-app or stop_grace_period: 30s in Compose.

Cause 3: killed from outside

A health-check based restart, an orchestrator, a CI timeout or a manual docker kill / kill -9 also produce 137. Check docker events and your orchestrator's logs for who issued the kill.

Last updated 2026-11-30.