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=5
Save 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
Extremely helpful. I have 12GB of RAM and docker was consuming almost 10GB.
I limited docker to 2GB and it's working better than after.
Thanks a lot.