YoTo Blog

Limit memory in WSL2 Docker


Settings window

If you go to the resources section of the Docker Desktop settings window, there is a description and it tells you to use the .wslconfig file.
If you go to the link, there are various settings. Docker Desktop Settings Screen

Settings method

  • C drive -> Users -> User ID -> Create .wslconfig file
    .wslconfig contents
[wsl2]
memory=4GB

Create a .wslconfig file in C:\Users[Windows account ID].
I will limit the memory to 4GB.

  • Reflect

To reflect, exit Docker Desktop.

Run PowerShell with administrator privileges and restart LxssManager.

Get-Service LxssManager | Restart-Service

Restart LxssManager

Check

Check Docker Desktop Memory You can see that the maximum memory is properly limited to 3.74GB.