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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With