Memory limits, reservations and swap
Container memory accounting includes more than application heap. A hard memory limit constrains memory charged to the cgroup; a memory reservation is a softer reclaim-related setting. Swap may extend the total memory budget at a latency cost, when host and runtime support it.
Worked example
This is an offline lesson. Scenarios are fictional and Docker commands are unexecuted. Any optional execution requires an approved disposable VM, a reviewed preloaded image with verified digest, blocked external access and appropriate resource limits. No resource exhaustion or host-policy change is required. Before any authorized optional observation, verify the effective daemon endpoint including overrides, exact object ID and observation window. Bound collection time and output bytes; do not generate resource pressure or export private telemetry. Mark unavailable measurements NOT RUN.
Fictional supported Linux host--memory=128m --memory-reservation=64m --memory-swap=192mRAM ceiling: 128 MiB; swap allowance: 64 MiBAlternative: --memory=128m --memory-swap=128m -> no swap allowance--memory-swap is a combined memory-plus-swap amount when positive and used with --memory. Equal values prevent container swap usage when supported. A value of -1 allows swap up to what is available on the host; omitted swap may allow additional swap by default. Zero is treated as unset. None of these settings creates physical RAM or guarantees latency. Page cache and other charges contribute to memory usage. A reservation is not exclusive allocated RAM. Check actual controller availability, parent limits and Docker Desktop VM budget before drawing conclusions. Use a small application with known peak requirements; avoid deliberate memory exhaustion. The practice allows at most 64 MiB of additional swap under the stated assumptions. Free swap reported inside a container can describe the host rather than the container allowance. A memory reservation is not a guaranteed minimum allocation; verify the effective memory and swap limits and the available host swap separately.
Common mistake
Do not interpret 192m as 192 MiB of additional swap in this example.
Manual practice
For memory=256m and memory-swap=320m, calculate the swap allowance and describe one reason observed swap can be lower.
Worksheet: lab-fixtures/docker-resource-management/02-memory/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Memory limits, reservations and swap — Knowledge check
Apply resource management reasoning in a fictional scenario.
With memory=128m and memory-swap=192m, how much additional swap is allowed?
What is a memory reservation?
What must be checked before interpreting swap?