Containers can crash even when they appear to be within memory limits, leaving developers scratching their heads. The culprit is the Linux Out-of-Memory (OOM) Killer, which can terminate processes to protect the host system.
Containers share the host kernel and use cgroups to manage resources, but they are not fully isolated like virtual machines. When the host runs low on memory, the OOM Killer may kill a process inside a container regardless of its individual memory limit. Understanding this kernel behavior is key to preventing unexpected restarts.
For developers using containers in production, monitoring host memory pressure and configuring appropriate limits for both the container and the host can help avoid these crashes.