Technical Anshu
Tutorials Blog
🐳 Docker Tuning

Limit Docker and WSL 2 Memory and CPU with the Wslconfig File

By default, WSL 2 may take up to half of your PC's memory - and on some builds far more - before it thinks about giving any back. One small text file with three lines puts you back in charge of your own machine.

✍️ Technical Anshu🪟 Windows 10 / 11⏱️ 6 minute read
🎥 Watch the full install in the video - WSL 2 setup and the first container, step by step

The symptom is familiar: a few containers running, and the whole PC turns sluggish because a process called Vmmem is sitting on gigabytes of RAM. Vmmem is the WSL 2 virtual machine, and Docker's engine lives inside it. WSL 2 grows its memory as guests demand it and is lazy about returning it. The fix is not a registry hack - it is Microsoft's own settings file, .wslconfig, and this page shows exactly what to put in it.

Notepad - C:\Users\YourName\.wslconfig (a sensible starting point)
[wsl2] memory=4GB processors=2 swap=2GB # save the file, then run: wsl --shutdown # wait a few seconds, then start Docker Desktop again
Three settings that end the Vmmem argument - cap the RAM, cap the cores, cap the swap
1

Create the File in the Right Place

  1. The file lives in your Windows user folder - the same folder that holds Documents and Downloads - as a file named exactly .wslconfig
  2. Create it with Notepad if it does not exist. Be careful Windows does not quietly save it as .wslconfig.txt - in the Save dialog, set the type to All Files
  3. Its full path reads like C:\Users\YourName\.wslconfig - it is per-user and applies to every WSL distro and to Docker's engine together
2

The Settings That Matter

Everything sits under a [wsl2] heading:

  1. memory=4GB - the maximum RAM the whole WSL 2 VM may use. On a 16 GB machine, 4 to 6 GB is a sane Docker allowance; on an 8 GB machine, start at 3 to 4 GB
  2. processors=2 - how many of your CPU cores the VM may use. Half your cores is a reasonable ceiling
  3. swap=2GB - the overflow file WSL uses when the memory cap is hit. Some swap prevents hard crashes; too much just moves the slowness to disk

Honest framing: these are ceilings, not reservations. WSL still only uses what it needs - you are setting the maximum damage, not pre-paying memory.

3

Apply It - the Shutdown Is the Step Everyone Misses

  1. Save the file
  2. Quit Docker Desktop completely
  3. In PowerShell run wsl --shutdown - this fully stops the WSL 2 VM. Editing the file without this does nothing, which is the source of most 'wslconfig does not work' complaints
  4. Wait a few seconds, start Docker Desktop again, and confirm in Task Manager that Vmmem now respects your ceiling under load
4

Tune Honestly, Do Not Starve It

A cap set too low does not crash Windows - it crashes your containers, with out-of-memory kills that look like application bugs. If containers start dying after you add limits, raise memory a step at a time. Match the cap to the work: one small database container is happy in 2 GB; a build pipeline or a local AI model is not, and pretending otherwise just moves the failure somewhere stranger.

🎥 Watch the Complete Process in the Video

Watch the video to get Docker running first - then use this file to keep it polite on a shared machine.

▶️ Watch Full Video
❓ Frequently Asked Questions

My .wslconfig changes are ignored. Why?

Almost always because the running VM never restarted. The file is only read when WSL 2 starts. Quit Docker Desktop, run wsl --shutdown, wait a few seconds, then start things again. The second cause is the classic one: Notepad saved the file as .wslconfig.txt - check the real filename in Explorer with file extensions visible.

What memory limit should I set on a 16 GB PC?

Start with memory=4GB or 6GB for general development. That leaves Windows and your browser comfortable while giving Docker real room. If you build large images or run several services together, raise it - the right number is the one where your containers stop being killed and your PC stays responsive.

Does .wslconfig limit Docker only, or all of WSL?

All of it. The settings apply to the single WSL 2 virtual machine that hosts every distro and the Docker engine together. There is no per-distro memory cap in this file - the ceiling is shared, which is worth remembering when Ubuntu and Docker seem to be competing.

This guide is based on the Technical Anshu Docker on WSL 2 video • Stuck on any step? Ask in the video comments — you will get a reply there 🙏