- Intermediate
- Memory and CPU
How it works
--memory 512m sets a hard limit enforced by the kernel's cgroups; --cpus 1.5 caps CPU time. In Compose, use mem_limit and cpus, or deploy.resources.limits. docker stats shows each container's usage against its limit.
What breaks
A limit below what the app really needs gets it killed over and over (exit code 137). Set limits from measured usage plus a margin, and keep their sum under the server's memory, with room left for the system.
In a terminal
docker run -d --name api --memory 512m --cpus 1 orders-api
docker stats --no-stream
See it break, then fix it
Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.