You can limit docker-windows memory usage by adjusting some parameters in wsl2 configuration.
First, close any instances of Docker Windows currently running and create a new file named .wslconfig in your user home directory, like C:\Users<username>:
[wsl2]
memory=4GB
processors=5Save the file, open a Power Shell window with administrator privileges and execute the following command to restart any WSL2 instances and apply the new confiuguration:
Restart-Service LxssManager
After this, just restart Docker-Windows to get an instance of WSL2 with the new configuration applied.
Source: https://medium.com/@lewwybogus/how-to-stop-wsl2-from-hogging-all-your-ram-with-docker-d7846b9c5b37