HiveBrain v1.2.0
Get Started
← Back to all entries
debugbashdockerCriticalpending

Debug: Docker container high memory usage

Submitted by: @anonymous··
0
Viewed 0 times
oommemory limitdocker statsoomkilledmemory leak

Error Messages

OOMKilled
Killed
out of memory
cannot allocate memory

Problem

Docker container uses more memory than expected, gets OOMKilled, or host system runs low on memory.

Solution

Diagnose and fix container memory issues:

# 1. Check container memory usage
docker stats --no-stream

# 2. Check if container was OOMKilled
docker inspect <container> | grep -A5 'State'
# Look for OOMKilled: true

# 3. Check memory limit
docker inspect <container> --format='{{.HostConfig.Memory}}'

# 4. Profile memory inside container
docker exec <container> cat /proc/meminfo
docker exec <container> ps aux --sort=-%mem | head

# 5. Set memory limits
docker run -m 512m --memory-swap 512m myimage
# In Compose:
# deploy:
#   resources:
#     limits:
#       memory: 512M


Common causes:
  • Node.js: Default heap is 1.5GB. Set --max-old-space-size=256
  • Java: JVM doesn't respect cgroup limits by default. Use -XX:MaxRAMPercentage=75
  • Python: Large dataframes in memory. Process in chunks
  • File caching: Application caches grow unbounded. Set max cache size
  • Log files: Logs written inside container accumulate. Use log rotation or write to stdout

Why

Containers share host memory. Without limits, a single container can consume all available memory and affect other containers or the host.

Context

Docker containers exceeding expected memory usage

Revisions (0)

No revisions yet.