Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory allocation to docker containers after moving to WSL 2 in Windows

Tags:

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. enter image description here

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?

like image 596
Murtaza Haji Avatar asked Jun 16 '20 09:06

Murtaza Haji


People also ask

How much memory is allocated to WSL2?

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.

How do I allocate more memory to Docker Windows?

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.

How much memory should I allocate to Docker?

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.

Where are Docker volumes stored Windows WSL2?

ls -l /var/lib/docker/volumes/Beta Was this translation helpful?

How to set memory allocation limits on Docker containers on WSL 2?

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.

What is dynamic memory allocation in Docker desktop?

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!

What is the difference between Docker desktop and WSL 2?

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.

Can I use WSL2 for Linux containers on Windows 10?

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.


1 Answers

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.

like image 177
Alexz Avatar answered Sep 20 '22 16:09

Alexz