Reputation:
I have a backend server program that launches docker containers using the Docker Engine API (Json API) and I would like to limit the number of CPU cores per docker container to e.g. 1.
The Docker Engine API documentation has several options to configure the CPU settings of a container, see https://docs.docker.com/engine/api/v1.24:
"HostConfig": {
"CpuPercent": 80,
"CpuShares": 512,
"CpuPeriod": 100000,
"CpuQuota": 50000,
"CpusetCpus": "0,1",
"CpusetMems": "0,1"
}
I could use CpusetCpus
for this but this is quite cumbersome as I need to keep a list of which docker containers are assigned to which CPU cores. (I don't care on which CPU core my container runs, I just want to avoid that it uses more than 1 CPU core.)
I could also set the CpuQuota
so that each docker container uses only e.g. 12.5% of all CPU cores, which corresponds to 1 CPU core on a server with 8 CPU cores. The problem with this approach is that if I run my backend program on a different server with a different number of CPU cores the CpuQuota
setting of 12.5% does not correspond to 1 CPU core anymore.
Both options above are cumbersome and far from ideal. There must be a better/simpler way to set the number of CPU cores per container?!
Upvotes: 3
Views: 1812
Reputation: 5624
You can set NanoCPUs
. 1000000000 units would equal 1 core.
Upvotes: 7