Docker container with no --memory limit can OOM the entire host, not just itself
docker stats shows MEM USAGE / LIMIT equal to total host RAM
host becomes unresponsive or SSH hangs under memory pressure, not just the containerWhat's happening
App-level heap caps (JVM -Xmx, Node --max-old-space-size, etc.) only limit what the application process tries to allocate — they do nothing to stop the container itself from being killed by the Linux OOM killer at the host level if no cgroup memory ceiling was ever set via `--memory` / `mem_limit`. Without an explicit container memory limit, `docker stats` reports the limit as the full host RAM, which means one container with a memory leak, a larger-than-expected workload, or just a busy day can push the entire host into OOM — taking down every other container, and sometimes even SSH access, not just the one container that grew too big.
Fix
1. Always set an explicit container memory ceiling, not just an app-level heap flag:
```yaml
services:
app:
mem_limit: 4g
memswap_limit: 4g
```
or `docker run --memory=4g --memory-swap=4g ...`.
2. Leave real headroom for the host OS itself (sshd, systemd, the container runtime) — don't set the container limit to 100% of host RAM. A common mistake is computing the ceiling from the VM's nominal/advertised RAM instead of what `/proc/meminfo` actually reports, which can be noticeably smaller once the provider's own overhead is subtracted.
3. An app-level heap cap is still worth setting (it gets you a cleaner GC-driven slowdown instead of a hard kill) but treat it as a second line of defense, not a replacement for the container-level limit.
4. Verify with `docker stats` that MEM LIMIT is actually your intended ceiling, not the full host RAM.
5. If the host becomes unresponsive (not just one container crashing) under memory pressure, that's the signature of this exact bug — a host-wide OOM, not a per-container one — and the fix is the container memory flag above, not more RAM.Got a different error? Paste it here for a free diagnosis.