Container killed due to out of memory
This status indicates that the container was terminated by the Linux kernel's Out Of Memory (OOM) killer. This happens when the container tries to consume more memory than its allocated limit, forcing the system to reclaim memory to prevent instability.
- 1Container memory limit is set too low for the application's workload.
- 2The application running inside the container has a memory leak.
- 3The host machine itself is running low on available physical memory.
- 4A sudden, temporary spike in traffic or processing caused a legitimate surge in memory usage.
A Node.js application container attempts to allocate memory beyond its 256MB limit, triggering the OOM killer.
# Run a container with a restrictive memory limit
docker run --name memory-hog --memory=256m -d your-app-image
# Let the app run and exceed its memory limit...
# Check the container's state to see if it was OOMKilled
docker inspect memory-hog --format="{{json .State}}"expected output
{
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": true,
"Dead": false,
"Pid": 0,
"ExitCode": 137,
"Error": "",
"StartedAt": "...",
"FinishedAt": "..."
}Fix 1
Increase the Container Memory Limit
WHEN When the application legitimately requires more memory for its workload.
# Increase memory limit to 512MB docker run --memory=512m your-app-image
Why this works
This directly allocates more memory to the container, providing more headroom before the OOM killer is invoked.
Fix 2
Profile and Fix Application Memory Leaks
WHEN When memory usage continually grows over time without stabilizing.
# Monitor real-time memory usage of a container docker stats your-container-name --no-stream
Why this works
Using tools like 'docker stats' or language-specific profilers helps identify parts of the application that are not releasing memory, allowing you to fix the underlying code.
Fix 3
Enable Swap Memory
WHEN To provide a buffer for temporary memory spikes, but not as a fix for leaks.
# Allow the container to use up to 1GB of swap docker run --memory=512m --memory-swap=1g your-app-image
Why this works
This allows the container to use disk-based swap space when it runs out of physical RAM, which is slower but can prevent termination during brief spikes.
✕ Remove the memory limit entirely in a production environment.
An unlimited container with a memory leak can consume all host memory, potentially crashing the host and all other containers running on it.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev