MAG
MAG

Reputation: 3075

How to specify the number of CPU a container will use?

I am on working on Windows Server 2019 and trying to run a docker container of CentOS on it. I am running the following:

PS C:\Windows\system32> docker run -dit --name=testing23 --cpu-shares=12    raycentos:1.0
6a3ffb86c1d9509a9d80f0de54fc6acf5731ca645ee74e6aabe41d7153b3af70
PS C:\Windows\system32> docker exec -it 6a3ffb86c1d9509a9d80f0de54fc6acf5731ca645ee74e6aabe41d7153b3af70 bash
(app-root) bash-4.2# nproc
2

It still specifies only 2, and not 32. How can we assign more CPUs to the container?

Upvotes: 1

Views: 2917

Answers (2)

Ashok
Ashok

Reputation: 3611

By default, all can be used, or you can limit it per container using the --cpuset-cpus parameter.

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

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

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

docker run --cpus 2.5 myapplication:latest

Upvotes: 0

ML85
ML85

Reputation: 715

refer to this topic for more details https://docs.docker.com/config/containers/resource_constraints/#cpu

you have to add the values with proper flags

try :

    --cpus=<value> for maximum CPU resources a container can use
    --cpuset-cpus = 12

Upvotes: 1

Related Questions