Skip to content

Resource limits: CPU, memory, swap and processes

Select an icon to see what it is.

Step 6 of 6

docker update changes limits live

docker update sends POST /containers/{id}/update with the new values. dockerd passes them down to runc, which writes them into the same cgroup files, and the running process keeps going. No restart is needed.

$ docker update --cpus 1 <container>
PrevNext

POST /v1.45/containers/a3b4c5d6e7f80910a3b4c5d6e7f80910a3b4c5d6e7f80910a3b4c5d6e7f80910/update

{
"NanoCpus": 1000000000
}

Try it yourself

Start a limited container, read the cgroup values, and change a limit live.

$ docker run -d --name limited --cpus 0.5 -m 256m --pids-limit 100 alpine sleep 1000
$ docker inspect --format 'cpus={{.HostConfig.NanoCpus}} mem={{.HostConfig.Memory}} pids={{.HostConfig.PidsLimit}}' limited
$ docker update --cpus 1 limited
$ docker stats --no-stream limited
$ docker rm -f limited

Quiz

1. What is the difference between --cpus and --cpu-shares?
2. What does --memory-reservation set?
3. How do you change a running container's CPU limit?