lucidbrot
lucidbrot

Reputation: 6251

Why does docker have more cpus available than the limit I set?

I'm running my container with

docker run --rm -it --cpus=1 --memory "8G" -v "$pwd":"/code/" 'algolab' bash 

This means according to the docs that the container will only use one cpu core.

--cpus=0.000 Number of CPUs.
Number is a fractional number. 0.000 means no limit.

But when I run nproc inside the container, it tells me it sees 8 cores - the same number as on my host.

This answer supports that claim. But it also mentions --cpuset-cpus="0-2". When I use that, in addition to --cpus=1, I get the result 3 from nproc.

Why is docker ignoring --cpus=1? And how do I make it stop ignoring it?


For now, I can use --cpuset-cpus="0", but I don't understand why that's necessary.


$ docker --version
Docker version 19.03.6, build 369ce74a3c

Upvotes: 4

Views: 2537

Answers (1)

Leonardo Dagnino
Leonardo Dagnino

Reputation: 3225

The --cpus option sets a quota on the CPU usage - this does not restrict which CPUs can be used nor how many at a time; this restricts the total slice of time they can be running on your CPU. So if you pass --cpus 1 on a machine with 8 cores, the container will be limited to running on 1/8th of your CPU time. This is covered on a different section of the docs.

Upvotes: 4

Related Questions