How do you set memory and CPU limits, and what happens when they are exceeded?
BeginnerProductionResource Limits, Health & Reliability
Answer
docker run -d --memory=512m --memory-swap=512m --cpus=1.5 app
Exceeding memory triggers the kernel OOM killer for that cgroup (exit 137, OOMKilled: true). Exceeding CPU only throttles the container (CFS quota), causing latency, not a crash. --memory-swap equal to --memory disables swap.
More on Resource Limits, Health & Reliability
What is the difference between `--cpus`, `--cpu-shares` and `--cpuset-cpus`?BeginnerWhat does `--memory-reservation` do?AdvancedHow do you diagnose an OOM-killed container?IntermediateWhy do JVM and Node services in containers need explicit memory flags?IntermediateWhat is CPU throttling, and how do you detect it?AdvancedHow do you limit PIDs and open files in a container?Beginner