137 docker resource_error ai_generated true

Container exited with code 137 (OOMKilled) - memory limit too low

ID: docker/container-oom-killed-memory-limit

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 24.0.7 active
Docker 25.0.3 active
containerd 1.7.13 active

Root Cause

Container exceeded its memory limit and was killed by the kernel OOM killer, typically due to insufficient --memory or -m setting.

generic

中文

容器超出了其内存限制,被内核OOM杀手终止,通常是由于--memory或-m设置不足。

Official Documentation

https://docs.docker.com/config/containers/resource_constraints/#memory

Workarounds

  1. 85% success Increase the memory limit when running the container: docker run -m 512m --memory-reservation 256m my_image
    Increase the memory limit when running the container: docker run -m 512m --memory-reservation 256m my_image
  2. 80% success Use docker stats to monitor actual usage and set limit 20% higher: docker stats <container_name>
    Use docker stats to monitor actual usage and set limit 20% higher: docker stats <container_name>
  3. 85% success For Docker Compose, add mem_limit in docker-compose.yml: services: app: mem_limit: 512m
    For Docker Compose, add mem_limit in docker-compose.yml: services: app: mem_limit: 512m

中文步骤

  1. 增加内存限制:docker run -m 512m --memory-reservation 256m my_image
  2. 使用docker stats监控实际使用量并设置高20%的限制:docker stats <container_name>
  3. 在docker-compose.yml中添加mem_limit:services: app: mem_limit: 512m

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Rebuilding the image with more layers doesn't change runtime memory limits; the limit is set at container start.

  2. 60% fail

    Adding swap space may delay the OOM but doesn't fix the underlying memory exhaustion; the container may still be killed or become unstable.

  3. 90% fail

    Restarting the container without changing memory limits just repeats the same crash.