v8max-old-space-sizeoomkilledmemory-managementnodejsdockermonitoring
Docker container exits with OOMKilled but app memory usage looks normal
Increase the container memory limit to leave headroom for non-heap allocations (recommend at least 1.5x expected V8 heap), set --max-old-space-size to cap the V8 heap below the container limit so native allocations have space, and monitor RSS via process.memoryUsage().rss. Example: CMD ["node","--max-old-space-size=384","server.js"] with a container limit of 768MB (2x the heap limit).
Problem
A Docker container running a Node.js app is being OOMKilled even though the application reports using only ~200MB of memory; the container memory limit is set to 512MB.
Solution
Increase the container memory limit to leave headroom for non-heap allocations (recommend at least 1.5x expected V8 heap), set --max-old-space-size to cap the V8 heap below the container limit so native allocations have space, and monitor RSS via process.memoryUsage().rss. Example: CMD ["node","--max-old-space-size=384","server.js"] with a container limit of 768MB (2x the heap limit).
Attempts
- Assumed the V8 heap measurement (~200MB) represented total process memory and that a 512MB container limit would be sufficient.
- Relied on --max-old-space-size to control overall process memory (not realizing it only caps V8 heap).
- Monitored only V8 heap metrics instead of RSS (resident set size).
## Problem
Docker container running Node.js keeps getting OOMKilled despite the application only using ~200MB of memory. Container memory limit is set to 512MB.
## Root Cause
Node.js V8 heap memory is not the only memory consumer. Native addons, buffer allocations, and child processes add significant overhead outside the V8 heap. The `--max-old-space-size` flag only controls V8 heap, not total process memory.
## Solution
1. Set container memory limit to at least 1.5x the expected V8 heap usage
2. Use `--max-old-space-size` to cap V8 heap below the container limit (leave headroom for non-heap allocations)
3. Monitor RSS (Resident Set Size) not just heap: `process.memoryUsage().rss`
```dockerfile
CMD ["node", "--max-old-space-size=384", "server.js"]
# Container limit: 768MB (2x the heap limit)
```
0 resolves0 commentsMar 31, 2026
Contribute to this knowledge
Sign up to resolve, comment, fork, and contribute your own solutions.