Skip to main content

On This Page

Docker OOM Kills: Diagnostic Workflows and Memory Limit Configuration

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Docker Out of Memory: How to Diagnose and Fix OOM Kills

The Linux kernel terminates Docker containers when they exceed memory thresholds, often leaving no application-level logs. Diagnostic confirmation requires checking for Exit Code 137 and the OOMKilled flag via docker inspect.

Why This Matters

In ideal cloud-native models, applications scale horizontally based on demand, but the technical reality is that memory leaks often trigger the kernel’s Out of Memory (OOM) Killer. Without explicit memory limits, a single leaking container can destabilize an entire host by consuming all available RAM, making proactive resource constraints essential for production stability.

Key Insights

  • Exit Code 137 indicates a process was killed by a signal, which, when paired with OOMKilled: true, confirms memory exhaustion.
  • Kernel logs accessible via sudo dmesg provide low-level details on which process was sacrificed and its RSS memory footprint at the time of death.
  • Containers with a MemoryLimit of 0 have no constraints, allowing them to consume 100% of host RAM.
  • Node.js applications can be constrained at the runtime level using the —max-old-space-size flag to manage heap usage.
  • The docker stats command provides live stream telemetry of container resource consumption for real-time monitoring.

Working Examples

Checking the container’s last exit code and OOM status

docker inspect <container_name> | grep -A 5 '"State"'

Checking kernel logs for OOM killer activity

sudo dmesg | grep -i "oom\|killed process" | tail -20

Setting memory limits in docker-compose.yml

services:
  app:
    image: your-image
    deploy:
      resources:
        limits:
          memory: 512M

Restricting Node.js heap usage to prevent container OOM

node --max-old-space-size=256 server.js

Practical Applications

  • Use Case: Production environments using docker-compose to enforce resource limits and prevent noisy neighbor issues. Pitfall: Neglecting to set memory limits, leading to host-wide OOM events that crash critical system services.
  • Use Case: Node.js microservices monitoring heap usage with process.memoryUsage() to identify leaks before kernel intervention. Pitfall: Relying solely on restart policies like —restart=unless-stopped to mask leaks rather than debugging memory growth.

References:

Continue reading

Next article

Optimizing Carbon-Negative Supply Chains with Explainable Causal Reinforcement Learning

Related Content