docker oom_error ai_generated partial

Container exited with code 137 (OOMKilled)

ID: docker/exit-code-137

Also available as: JSON · Markdown
80%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
27 active

Root Cause

Container killed by OOM killer (exit code 137 = SIGKILL). Exceeded memory limit.

generic

Workarounds

  1. 90% success Increase memory limit: docker run --memory=2g or in compose: mem_limit: 2g
    docker run --memory=2g or in compose: mem_limit: 2g

    Sources: https://docs.docker.com/engine/containers/resource_constraints/#limit-a-containers-access-to-memory

  2. 85% success Profile application memory to find leaks or reduce footprint
    # Check memory usage of running container:
    docker stats <container>
    
    # Profile inside container:
    apt-get install -y procps && top
    
    # For Node.js, reduce heap:
    NODE_OPTIONS=--max-old-space-size=512 node app.js
    
    # For Python, use tracemalloc or memory_profiler

    Sources: https://docs.docker.com/engine/containers/resource_constraints/

  3. 88% success For build-time OOM, increase Docker Desktop memory in Settings > Resources
    # Docker Desktop > Settings > Resources
    # Increase Memory to at least 4GB (default is 2GB)
    # Increase Swap to 2GB
    # Click 'Apply & Restart'
    
    # For colima:
    colima start --memory 4 --cpu 4

    Sources: https://docs.docker.com/desktop/settings-and-maintenance/settings/

Dead Ends

Common approaches that don't work:

  1. Set --oom-kill-disable 85% fail

    System may freeze if container consumes all host memory

  2. Remove memory limit entirely 70% fail

    Container may consume all host memory and kill other processes

Error Chain

Frequently confused with: