← All notes

Docker memory and CPU limits (--memory, --cpus)

Answer: --memory (-m) sets the maximum amount of memory the container can use. --cpus specifies how much of the available CPU resources a container can use. By default, a container has no resource constraints and can use as much of a resource as the host's kernel scheduler allows.

Examples

docker run -m 512m --memory-swap 512m myapp
docker run -m 1g --memory-reservation 768m myapp
docker run --cpus 1.5 myapp
docker run --cpuset-cpus 0,1 --cpu-shares 512 myapp
docker run --pids-limit 200 myapp
docker stats

Memory options

| Option | Description | |---|---| | -m, --memory | maximum memory the container can use; minimum 6m | | --memory-swap | total memory plus swap; only has meaning if --memory is also set | | --memory-reservation | soft limit smaller than --memory, used on contention or low memory | | --memory-swappiness | 0 to 100; 0 turns off anonymous page swapping | | --oom-kill-disable | only use together with -m |

CPU options

| Option | Description | |---|---| | --cpus | how much of the available CPU resources a container can use | | --cpu-period / --cpu-quota | CFS period and quota; --cpus is a more convenient alternative | | --cpuset-cpus | limit specific CPUs or cores, such as 0-3 or 1,3 | | --cpu-shares | relative weight, default 1024; only enforced when CPU cycles are constrained |

Rules

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Resource constraints; Docker CLI reference, docker container run. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Resource constraints; Docker CLI reference, docker container run. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.

Cite this

Permanent ID: iil:note:xjp92mrd

iinventedlight. 2026. "Docker memory and CPU limits (--memory, --cpus)." iinventedlight Library, iil:note:xjp92mrd, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-resource-constraints/. License: CC-BY-4.0.

@misc{iil_note_xjp92mrd,
  author = {{iinventedlight}},
  title = {{Docker memory and CPU limits (--memory, --cpus)}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/docker-resource-constraints/},
  note = {Permanent ID iil:note:xjp92mrd. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-resource-constraints.md.