How to Stop WSL2 from Hogging All Your Ram With Docker

Lew C
2 min readMay 24, 2020
Photo by Liam Briese on Unsplash

There’s no doubt about it, WSL2 (Windows Subsystem for Linux 2) has a host of performance benefits for everyone doing Linux related work on Windows. For me personally, it has significant performance benefits in Docker. My docker-compose usages feel snappier and my containers come up about 50% quicker.

The only downside of this, is that previously, I was using a Hyper-V image that ran my Docker engine. This is just how things work when using Docker on Windows. Of course, when you are using this solution, you can just limit the CPU’s and memory on the Docker virtual machine.

With WSL2 however, this explicitly doesn’t create a virtual machine that you can configure in Hyper-V. Instead, it does something else (I’m a little sketchy on what exactly, but it’s a more integrated experience than starting a virtual machine running Linux for your Docker containers).

The upside of this is that it’s a lot more performant. The downside is that in my experience, WSL2 will happily consume all your memory and CPU and pretty much starve out the host operating system, making all your Docker work really grindy and slow. The reason why is because you start your Docker containers on WSL2 through docker compose, and it seems like it just builds your images and hosts them while provisioning 100% of your computer’s resources…

--

--

Lew C
Lew C

Written by Lew C

I code, and then I write about it.

Responses (25)