Docker Container Memory Limits
My container keeps getting OOM killed. How do I debug this?
Run `docker stats` to monitor real-time memory usage. Also check `docker inspect <container_id>` for the memory limit configuration. Look at `/sys/fs/cgroup/memory/memory.max_usage_in_bytes` inside the container for peak usage.
Should I set memory limits on all containers?
Yes, always. Without limits, one runaway container can starve others. Set both memory and memory-swap limits explicitly. A good starting point is 2-4x what the container typically uses.
What's the difference between memory and memory-swap limits?
Memory limit is RAM only. Memory-swap is RAM + swap combined. If you set --memory=512m and --memory-swap=1g, the container can use 512MB RAM and 512MB swap. Set them equal to disable swap entirely.
How do I see why a container was killed?
Check `docker inspect <container_id> --format='{{.State.OOMKilled}}'`. Also check system logs with `dmesg | grep -i kill` for OOM killer activity. In Kubernetes, use `kubectl describe pod` to see termination reasons.