Skip to main content
Containers and the underlying Docker host share the same kernel and the same physical resources (CPU, memory, block I/O, etc.). Without explicit limits, any container can consume as much of the host’s resources as it can, potentially starving other containers or the host itself.
Running containers without resource limits can allow a single container to exhaust host resources (CPU, memory, I/O), destabilizing other containers or the host. Always set appropriate limits in production.
A presentation slide titled "cgroups · resource limits" with a card labeled "without cgroups" showing CPU and RAM usage each at 100%. Both metrics are shown as orange progress bars at full capacity.
Docker leverages Linux cgroups (control groups) to restrict and account for the hardware resources available to each container. When you create a container with docker run, you can apply resource controls using flags that map to cgroups features. These controls help ensure predictable performance and isolation for workloads on the same host. How common resource flags behave:
  • --cpus: Limits CPU time available to the container as a decimal number of CPUs. Example: --cpus=0.5 allows up to 50% of a single CPU. On multi-core hosts, the total fraction of host CPU time depends on core count (e.g., 0.5 CPU on a 4-core host equals 12.5% of aggregate CPU time).
  • --memory: Sets a maximum resident set size for container processes. Use suffixes like b, k, m, or g (bytes, kilobytes, megabytes, gigabytes). If the container tries to exceed this limit, the kernel may invoke the OOM killer.
  • --cpuset-cpus: Pins container processes to specific CPU cores (e.g., --cpuset-cpus="0,2").
  • --memory-swap: Controls swap usage combined with --memory. If not set, Docker may allow swap up to system defaults; setting it equal to --memory disables swap.
  • --pids-limit: Limits the number of processes (PIDs) the container can create, which prevents fork bombs from impacting the host.
  • --blkio-weight: Sets block I/O weight (relative priority) for container disk I/O.
Common Docker resource flags (quick reference): Examples
You can combine multiple limits (CPU, memory, I/O, PIDs) when starting a container for predictable resource usage. For more fine-grained control, use flags like --memory-swap, --cpuset-cpus, and --blkio-weight. Monitor containers and tune limits to match workload characteristics.
Additional notes and references That’s it for now on Docker Engine.

Watch Video