Limiting the docker daemon CPU resource
On windows, open up powershell and type
# turn off all wsl instances such as docker-desktopwsl --shutdownnotepad "$env:USERPROFILE/.wslconfig"
Edit .wslconfig
file with notepad and write down these settings:
[wsl2]memory=3GB # Limits VM memory in WSL 2 up to 3GBprocessors=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_64CPUs: 2Total Memory: 6.789GiB
Credits to Ali Bahraminezhad, check out his post here
As specified in the docker documentation you can limit the container resources usage by specifying the --cpus
flag when running.The docker info command is returning the number of cpus on the machine.
To limit the container to use only one cpus use the following:
docker run --cpus="1" ...
Yo can limit resources to docker using docker machine. In other words you can limit resources assigned to virtual machine itself from your VM provider itself.
To create a new docker machine and specify its configurations:
docker-machine create -d virtualbox --virtualbox-memory=4096 --virtualbox-cpu-count=2 --virtualbox-disk-size=50000 nameOfYourMachine
To modify current one you can use VBoxManage
that comes with Virtualbox
, stop VM first, change settings and start it again.
docker-machine stopVBoxManage modifyvm default --cpus 1VBoxManage modifyvm default --memory 4096docker-machine start
In Mac or windows where you have GUI, you can easily limit the docker resources CPU/memory from Preferences or Settings menu as shown below.