Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting the docker daemon CPU resource

When I do docker info it gives me the following result:

OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 2
Total Memory: 7.632 GiB

but I want the cpu to be 1 and not 2.How do I restrict the CPU for the docker itself?

like image 856
Shadab Avatar asked Oct 06 '17 05:10

Shadab


People also ask

How do I limit CPU usage in docker container?

To control a container's CPU usage, you can use the --cpu-period and --cpu-quota options with the docker create and docker run commands from version 1.7. 0 of Docker onward.

Can I limit the file size CPU utilization for a docker in my machine?

Limit Docker Container CPU Usage You can also use the --cpu-shares option to give the container a greater or lesser proportion of CPU cycles. By default, this is set to 1024. To find more options for limiting container CPU usage, please refer to Docker's official documentation.

How many CPUs should docker use?

Performance and Containers If no value is provided docker will use a default value. On windows, a container defaults to using two CPUs. If hyperthreading is available this is one core and two logical processors. If hyperthreading is not available this is two cores and two logical processors.

Can docker use all CPUs?

By default, Docker does not apply any CPU limitations. Containers can all of the hosts given CPU power. Relax, a Docker container will not consume the entire CPU power of your physical host. If you are using Docker Desktop, the host I mentioned, it is a virtualized host, responsible for running your Docker containers.


1 Answers

On windows, open up powershell and type

# turn off all wsl instances such as docker-desktop
wsl --shutdown
notepad "$env:USERPROFILE/.wslconfig"

Edit .wslconfig file with notepad and write down these settings:

[wsl2]
memory=3GB   # Limits VM memory in WSL 2 up to 3GB
processors=2 # Makes the WSL 2 VM use two virtual processors

type wsl in powershell

restart docker

type docker info and you should see something like

Architecture: x86_64
CPUs: 2
Total Memory: 6.789GiB

Credits to Ali Bahraminezhad, check out his post here

like image 59
Daniel Botero Correa Avatar answered Sep 18 '22 17:09

Daniel Botero Correa