How many CPUs does a docker container use?

docker

Solution

As Charles mentions, by default all can be used, or you can limit it per container using the `--cpuset-cpus` parameter.

docker run --cpuset-cpus="0-2" myapp:latest

That would restrict the container to 3 CPU's (0, 1, and 2). See the docker run docs for more details.

The preferred way to limit CPU usage of containers is with a fractional limit on CPUs:

docker run --cpus 2.5 myapp:latest

That would limit your container to 2.5 cores on the host.

Lastly, if you run docker inside of a VM, including Docker for Mac, Docker for Windows, and docker-machine, those VM's will have a CPU limit separate from your laptop itself. Docker runs inside of that VM and will use all the resources given to the VM itself. E.g. with Docker for Mac you have the following menu:

Problem

Lets say I am running a multiprocessing service inside a docker container spawning multiple processes, would docker use all/multiple cores/CPUs of the host or just one?

Original source