Skip to content
FR
  1. LuzineDebug
  2. Docker & DevOps
  3. web-1 exited with code 137
Docker & DevOps Intermediate ≈ 20 min to fix

Fix "exited with code 137" (OOMKilled) in Docker and Kubernetes

Error message
web-1 exited with code 137
  • Reason: OOMKilled
  • ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 137
  • Memory cgroup out of memory: Killed process 4127 (node) total-vm:4318820kB, anon-rss:1046528kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:3164kB oom_score_adj:0
  • command terminated with exit code 137
  • "OOMKilled": true
In short

Code 137 means the process was killed by SIGKILL (128 + 9), almost always by the kernel because the container exceeded its memory limit (OOMKilled). Confirm with docker inspect or kubectl describe pod, measure the real usage, then raise the limit or reduce the memory the application uses.

Be the first to confirm this fix

What this error means

An exit code above 128 means death by signal: 137 = 128 + 9, which is SIGKILL. That signal cannot be caught: no stack trace, no application log, the process just vanishes. Most often it is the kernel OOM killer: the container cgroup memory reached its limit (docker run -m, Compose mem_limit, Kubernetes resources.limits.memory), or the Docker Desktop VM ran out of RAM. Docker then records State.OOMKilled: true and Kubernetes shows Reason: OOMKilled. If OOMKilled is false, the SIGKILL came from somewhere else: docker kill, or a docker stop whose grace period expired.

Common causes

  1. Limit too low for the real need: JVM, Next.js or Vite build, loading an ML model, large import.
  2. Leak or unbounded growth: in-memory cache never cleared, whole file loaded into RAM, too many workers (Gunicorn, PHP-FPM pm.max_children).
  3. Runtime tuned above the limit: Node --max-old-space-size or JVM -Xmx larger than the container memory.
  4. Docker Desktop VM too small (macOS, Windows): all containers and builds share the memory set in Settings > Resources.
  5. Not a memory problem: the application ignores SIGTERM (often a shell-form CMD, where sh is PID 1) and Docker kills it after 10 seconds.

Step-by-step fix

  1. Confirm it really is an OOM

    true 137 confirms an OOMKilled. On a Linux host, the kernel log shows which process was killed and at what usage. With Docker Desktop that log lives inside the VM: rely on docker inspect.

    bash
    docker compose ps -a
    docker inspect --format '{{.State.OOMKilled}} {{.State.ExitCode}}' $(docker compose ps -aq web)
    sudo dmesg -T | grep -iE 'killed process|out of memory'
  2. Measure the real usage

    Compare MEM USAGE and LIMIT during the load that triggers the crash. On Kubernetes, kubectl top needs metrics-server, and kubectl describe pod shows Last State: Terminated with Reason: OOMKilled.

    bash
    docker stats --no-stream
    kubectl top pod --containers
    kubectl describe pod api-7d9f8b6c5d-x2kqp
  3. Docker and Compose: adjust the limit

    Give the container a limit above the measured peak, with some margin. docker compose applies deploy.resources.limits even outside Swarm; mem_limit: 1g works too. On the command line: docker run -m 1g myapp:latest. On macOS and Windows, also raise the VM memory in Docker Desktop.

    yaml
    services:
      web:
        image: myapp:latest
        deploy:
          resources:
            limits:
              memory: 1g
  4. Kubernetes: set requests and limits

    The limit is the ceiling above which the container is killed; the request is used to place it on a node. Base them on measured usage, not on a random value, then apply with kubectl apply.

    yaml
    resources:
      requests:
        memory: "512Mi"
        cpu: "250m"
      limits:
        memory: "1Gi"
  5. Make the runtime fit under the limit

    Set the heap below the container limit to leave room for the rest of the process, and reduce the number of workers if each one uses a lot. Example for a 1 GB limit.

    bash
    export NODE_OPTIONS=--max-old-space-size=768
    export JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75.0
    gunicorn --workers 2 --bind 0.0.0.0:8000 myproject.wsgi:application
  6. If OOMKilled is false: handle SIGTERM

    The container was killed while stopping. Use the exec form of CMD so the application is PID 1 and receives SIGTERM, handle that signal in the code, and extend the delay if a clean shutdown takes time (stop_grace_period: 30s in Compose, terminationGracePeriodSeconds in Kubernetes).

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

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Always set a memory limit and an alert around 80% (for example on container_memory_working_set_bytes with Prometheus).
  • Process large files as streams (streams, cursors, batches) rather than loading everything into memory.
  • Run a load test before setting limits, and review them after every significant change (new dependency, new model, more workers).

Frequently asked questions

Does exit code 137 always mean out of memory?

No: 137 only means SIGKILL. Check State.OOMKilled (Docker) or Reason: OOMKilled (Kubernetes). If it is false, look for a docker kill, a stop that exceeded the grace period or a failing liveness probe.

Why is there no error message in my application logs?

Because SIGKILL stops the process instantly, without giving it time to write anything. The only traces are in docker inspect, kubectl describe or the kernel log.

How do I fix "exit code: 137" during docker build?

A build step (often npm run build) ran out of memory. Raise the memory of Docker Desktop or of the CI runner, or cap the Node heap with NODE_OPTIONS=--max-old-space-size=... in that step.

Useful tools for this error

More Docker & DevOps errors

All Docker & DevOps errors →