I recently updated my Docker environment to run on WSL 2
on Windows.
For setting memory allocation limits on containers in previous versions, I had option in Docker Desktop GUI under Settings->Resources->Advanced->Preferences
to adjust memory and CPU allocation.
After WSL 2 integration, I am not able to find that option.
I assume I should run everything through my Linux distro from now on, so this is the solution I was able to find:
docker run -d -p 8081:80 --memory="256m" container_name
I dont want to have to set a flag each time when running a container. Is there a way to permanently set the memory allocation?
According to Microsoft's documentation, the amount of RAM that gets allocated to WSL depends on your Windows build number. On machines running build 20175 or higher, RAM is limited to either 50% of your total memory or 8GB, whichever happens to be smaller.
Set Maximum Memory Access To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.
Limit a container's access to memory The maximum amount of memory the container can use. If you set this option, the minimum allowed value is 6m (6 megabytes). That is, you must set the value to at least 6 megabytes. The amount of memory this container is allowed to swap to disk.
ls -l /var/lib/docker/volumes/Beta Was this translation helpful?
I recently updated my Docker environment to run on WSL 2 on Windows. For setting memory allocation limits on containers in previous versions, I had option in Docker Desktop GUI under Settings->Resources->Advanced->Preferences to adjust memory and CPU allocation. After WSL 2 integration, I am not able to find that option.
Docker Desktop uses the dynamic memory allocation feature in WSL 2 to greatly improve the resource consumption. This means, Docker Desktop only uses the required amount of CPU and memory resources it needs, while enabling CPU and memory-intensive tasks such as building a container to run much faster. Dynamic memory allocation and more CPU power!
This means, Docker Desktop only uses the required amount of CPU and memory resources it needs, while enabling CPU and memory-intensive tasks such as building a container to run much faster. Additionally, with WSL 2, the time required to start a Docker daemon after a cold start is significantly faster.
In the next session I will configure Docker to use WSL2 for Linux containers on Windows 10. Now that we have installed WSL2, we can configure it on Docker Desktop for Windows.
The Memory and CPU settings were removed for WSL2 integration. However, starting in Windows Build 18945, there is a workaround to limit WSL2 memory usage.
Create a %UserProfile%\.wslconfig
file for tweaking WSL2 settings:
[wsl2] memory=6GB # Any size you feel like swap=0 localhostForwarding=true
Run Get-Service LxssManager | Restart-Service
in an admin Powershell (or reboot) and verify that the vmmem
usage in Task Manager drops off.
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