Skip to content

Resource limits: CPU, memory, swap and processes

Select an icon to see what it is.

Step 1 of 6

Flags become HostConfig fields

Every limit flag turns into a number in HostConfig of the create request. Memory values are bytes and --cpus becomes NanoCpus. The kernel enforces them through the container's cgroup, as the earlier cgroups lesson showed for memory.

$ docker run -d --cpus 0.5 --cpu-shares 512 -m 256m --memory-reservation 128m --memory-swap 512m --pids-limit 100 alpine sleep 1000
PrevNext

POST /v1.45/containers/create

{
"Image": "alpine"
"HostConfig": {
"NanoCpus": 500000000
"CpuShares": 512
"Memory": 268435456
"MemoryReservation": 134217728
"MemorySwap": 536870912
"PidsLimit": 100
}
}