How to Stop WSL2 from Hogging All Your Ram With Docker

I have been doing some performance testing using Docker, Docker-Compose. I was running into an issue, my Dev laptop was showing that Docker (vmmem) was using 90% of my system RAM. That is not great, nor what I want when running performance tests. Several times during my tests my system literally crashed and died :).

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.

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 to those environments. My observation, pretty quickly your host OS runs out of RAM and so do your containers, and everything drags to a crawl. Fortunately it seems pretty easy to fix.

Setting boundaries for WSL2

We need to set some reasonable resource constraints on what WSL2 can actually use. Fortunately, that’s as simple as going to c:\users\<your your profile name> and creating a .wslconfig file. On my setup, a Dell Precision 5550, i7-10750H CPU @ 2.6GHz, 1 socket, 6 cores, 12 logical processors with 32 GB RAM mine looks like this:

memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=5 # Makes the WSL 2 VM use two virtual processors

Now you can restart docker. After a full restart of Docker, let’s checkout the Vmmem process.

Now you should be able to use Docker on your Windows 10 machine without having it use every ounce of available resources.

Using Docker to build Test Execution Infrastructure

Yesterday, I was having a lot of fun building stuff. I am a big fan of Docker and now learning Podman as well. Yesterday was about using Docker, Docker-Compose, WSL2 and building a cloud-ready approach to Engineering for Quality.

This project goal is to build a sample test execution infrastructure and supporting tools using Docker, Docker-Compose.

What is the recipe?

  • System under Test – YouTube
  • Auto-Scalable UI test automation execution infrastructure – Zalenium
  • Scalable AI-powered Test Automation Dashboard, acquire, aggregate and analyze test reports to ascertain release health – Report Portal (
  • Test Automation Code – Java, Selenium Webdriver, TestNg, Cucumber, Log4j2, using Cucumber Archetype (,
  • Development approach: Behavior Driven Development

Note: All components run inside a Docker Container, running on native Linux (WSL2). Developed and debugged using VS Code remote WSL debugging plugin. This allows me to connect my VS Code to my Linux WSL container. Super awesome stuff.

I will post a micro tutorial video later this week, showing all the above in action 🙂

What is next… taking this generic approach and apply it to GCP. I have already done this on Azure, so now it time to try Google.