I want to limit the number of cores that a docker container uses.
I have found the documentation and I can see that I can use --cpus as in
docker run -it --cpus=".5" ubuntu /bin/bash
but I don't understand what this setting actually represents. In the documentation example it uses 0.5 which indicates 50% of the CPU (so a percentage)
however in this other example it uses the command
--cpus=2
to set "the maximum number of CPUs that a container can use. For example, to limit a container to using two CPUs"
so which is which? a percentage or not
In my case for example I have a workstation of X cores and I want to limit it to Y cores. What should I put?
From https://docs.docker.com/config/containers/resource_constraints/ :
--cpusspecifies--cpu-quotawhich specifies the maximum cpu time the container will get per some period.Also https://kernel.googlesource.com/pub/scm/linux/kernel/git/glommer/memcg/+/cpu_stat/Documentation/cgroups/cpu.txt .
Effectively, setting
--cpus=2will set--cpu-quote = 2 * --cpu-periodwhich means that each 100 milliseconds the process will be maximally able to use 200 milliseconds on all cores, which effectively limits it to 2 cores.Both. A "core" is a virtual CPU. CPU here represents a core if your computer has like one cpu with many cores.
--cpus=Yor--cpuset-cpus=0-Y.