- Intermediate
- Memory and CPU
How it works
With --memory set and no --memory-swap, a container may also use as much swap as memory. Setting --memory-swap equal to --memory forbids swap for that container: it is killed at its limit instead of dragging the server down.
What breaks
A server that swaps shows no crash, only latency climbing for every service: timeouts, failing healthchecks, slow databases. docker stats and free -m make it visible; the fix is a limit on the service that grows.
In a terminal
docker run -d --name api --memory 256m --memory-swap 256m orders-api
free -m
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.