Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Reclaim Tons of Disk Space by Compacting Your Docker Desktop WSL 2 VM


We'll go over how to regain lots of disk space by compacting the VM file that Docker Desktop creates. I ended up getting 50gb back.

Quick Jump: Going Over All of the Steps

Last year I made that WSL 2 gotchas video about getting back disk space but it didn’t include shrinking down the Docker Desktop WSL 2 VM itself which is what this new video focuses on. We’ll go over how to prune images with Docker too.

Everything we’ll go over will work for all editions of Windows 10.

Going Over All of the Steps


You’ll want to open PowerShell as an admin and then run these commands:

# Close all WSL terminals and run this to fully shut down WSL.
wsl.exe --shutdown

# Replace Nick with your Windows user name. This is where Docker stores its VM file.
cd C:\Users\Nick\AppData\Local\Docker\wsl\data

# Compact the Docker Desktop WSL VM file and you're done.
# NOTE: This may not work with Windows Home edition (read below).
optimize-vhd -Path .\ext4.vhdx -Mode full

If you’re using Windows Home edition and optimize-vhd isn’t a valid command you can try running these commands instead:

# Replace Nick with your Windows user name.
select vdisk file="C:\Users\Nick\AppData\local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk


  • 0:17 – Vacuuming your Docker Desktop WSL 2 VM disk is really important
  • 0:38 – Pruning dangling and maybe old images with docker system prune
  • 2:43 – Launching PowerShell as admin
  • 3:12 – Shrinking the Docker Desktop WSL 2 VM for all editions of Windows
  • 5:21 – Restarting Docker and opening a regular WSL 2 terminal
  • 6:09 – Double checking your disk space to see if it’s reclaimed

How much space did you get back? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.