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.

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.5allows 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 likeb,k,m, org(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--memorydisables 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.
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.- For production clusters, consider orchestrators (like Kubernetes) that provide scheduling and resource guarantees across nodes.
- Docker documentation: https://docs.docker.com/config/containers/resource_constraints/
- Linux cgroups overview: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html