Skip to content

Container crashes on startup: OOM killed

Quick summary

Your container was OOM killed — it tried to use more memory than the configured limit.

Why this happens

  • The container memory limit is set too low for the application's actual memory needs

  • A memory leak in the application causes memory usage to grow unbounded over time

  • The application loads large files or datasets into memory at startup

Minimal example

✗ Broken code
# docker-compose.yml
services:
  app:
    image: myapp:latest
    mem_limit: 128m # too low — app needs 512m
    # Container gets OOM killed on startup
✓ Fixed code
# docker-compose.yml
services:
  app:
    image: myapp:latest
    mem_limit: 512m # adequate for app
    mem_reservation: 256m # soft limit
    # Container starts and runs stably

Setting the memory limit to 512m gives the application enough headroom to start and run without being OOM killed.

How to diagnose

  • Check the container logs for 'OOMKilled' or 'Out of memory' exit status

  • Monitor memory usage with docker stats or container memory metrics

  • Compare the configured memory limit with the application's expected memory usage

How to fix

  • Increase the container memory limit to accommodate the application's needs

  • Fix memory leaks in the application by profiling and identifying retained objects

  • Optimize the application to use streaming or lazy loading instead of loading everything into memory

How to prevent

  • Set appropriate memory limits based on load testing and monitor memory usage

  • Use memory profiling in development to detect leaks before deployment

Related Resources

Related Glossary

Related Lessons

← Back to language