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

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

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

Confirm It's an OOM Kill

Check Current Memory Usage

Set a Memory Limit

Find the Memory Leak in Your App

Restart Policy as a Temporary Bandaid

Prevention Checklist Your container keeps dying and you don't know why. No error in the app. No crash message. Just — gone. Nine times out of ten, the kernel killed it for using too much memory. Here's how to know for sure and fix it. An OOM kill shows "OOMKilled": true: Exit code 137 = killed by signal. Combined with OOMKilled: true = out of memory. Also check kernel logs: You'll see something like: If MemoryLimit is 0, there's no limit set — the container can eat all available RAM. Or in docker-compose.yml: For Node.js apps specifically: This doesn't fix the leak but keeps the service alive while you investigate. I built ARIA to solve exactly this.

Try it free at step2dev.com — no credit card needed. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to ? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# Check the container's last exit code -weight: 500;">docker inspect <container_name> | grep -A 5 '"State"' # Check the container's last exit code -weight: 500;">docker inspect <container_name> | grep -A 5 '"State"' # Check the container's last exit code -weight: 500;">docker inspect <container_name> | grep -A 5 '"State"' "OOMKilled": true "State": { "Status": "exited", "Running": false, "OOMKilled": true, "ExitCode": 137 } "State": { "Status": "exited", "Running": false, "OOMKilled": true, "ExitCode": 137 } "State": { "Status": "exited", "Running": false, "OOMKilled": true, "ExitCode": 137 } -weight: 600;">sudo dmesg | grep -i "oom\|killed process" | tail -20 -weight: 600;">sudo dmesg | grep -i "oom\|killed process" | tail -20 -weight: 600;">sudo dmesg | grep -i "oom\|killed process" | tail -20 Out of memory: Kill process 12345 (node) score 847 or sacrifice child Killed process 12345 (node) total-vm:2048000kB, anon-rss:1834000kB Out of memory: Kill process 12345 (node) score 847 or sacrifice child Killed process 12345 (node) total-vm:2048000kB, anon-rss:1834000kB Out of memory: Kill process 12345 (node) score 847 or sacrifice child Killed process 12345 (node) total-vm:2048000kB, anon-rss:1834000kB # Live container stats -weight: 500;">docker stats --no-stream # Check if a memory limit is set -weight: 500;">docker inspect <container_name> | grep -i memory # Live container stats -weight: 500;">docker stats --no-stream # Check if a memory limit is set -weight: 500;">docker inspect <container_name> | grep -i memory # Live container stats -weight: 500;">docker stats --no-stream # Check if a memory limit is set -weight: 500;">docker inspect <container_name> | grep -i memory MemoryLimit # Run with limit -weight: 500;">docker run -m 512m your-image # Or -weight: 500;">update a running container -weight: 500;">docker -weight: 500;">update --memory 512m --memory-swap 512m <container_name> # Run with limit -weight: 500;">docker run -m 512m your-image # Or -weight: 500;">update a running container -weight: 500;">docker -weight: 500;">update --memory 512m --memory-swap 512m <container_name> # Run with limit -weight: 500;">docker run -m 512m your-image # Or -weight: 500;">update a running container -weight: 500;">docker -weight: 500;">update --memory 512m --memory-swap 512m <container_name> services: app: image: your-image deploy: resources: limits: memory: 512M services: app: image: your-image deploy: resources: limits: memory: 512M services: app: image: your-image deploy: resources: limits: memory: 512M # Get a shell in the container -weight: 500;">docker exec -it <container_name> sh # Check process memory inside container top # or cat /proc/meminfo # Get a shell in the container -weight: 500;">docker exec -it <container_name> sh # Check process memory inside container top # or cat /proc/meminfo # Get a shell in the container -weight: 500;">docker exec -it <container_name> sh # Check process memory inside container top # or cat /proc/meminfo # Check heap usage node --max-old-space-size=256 server.js # Add memory monitoring node -e "setInterval(() => console.log(process.memoryUsage()), 5000)" & # Check heap usage node --max-old-space-size=256 server.js # Add memory monitoring node -e "setInterval(() => console.log(process.memoryUsage()), 5000)" & # Check heap usage node --max-old-space-size=256 server.js # Add memory monitoring node -e "setInterval(() => console.log(process.memoryUsage()), 5000)" & -weight: 500;">docker run ---weight: 500;">restart=unless-stopped -m 512m your-image -weight: 500;">docker run ---weight: 500;">restart=unless-stopped -m 512m your-image -weight: 500;">docker run ---weight: 500;">restart=unless-stopped -m 512m your-image -weight: 500;">docker stats watch -n 5 -weight: 500;">docker stats --no-stream - [ ] Always set --memory limits in production - [ ] Set up alerting when container memory > 80% - [ ] Add heap dump tooling to Node/Java apps - [ ] Monitor with -weight: 500;">docker stats in a loop: watch -n 5 -weight: 500;">docker stats --no-stream