Quick answer
A WSL disk (ext4.vhdx) and Docker Desktop's disk (docker_data.vhdx on Windows, Docker.raw on a Mac) grow as you add data but do not shrink when you delete files inside them. Never delete the file itself: it holds the whole Linux system or every image. Prune inside first with docker system prune, then compact the disk.
On this page
Why the disk files keep growing
WSL 2 keeps each Linux distribution in one virtual hard disk file, ext4.vhdx. Microsoft says WSL "automatically resizes these VHD files to meet storage needs", and each one can grow to a maximum of 1 TB by default. This is often the biggest single file in what fills a Windows C: drive.
Microsoft's diskpart docs say such disks "do not automatically reduce in size when you delete files". So rm inside Linux frees space for Linux, not for Windows.
Docker Desktop works the same way. On Windows with the WSL 2 engine, it keeps images, containers, volumes and build cache in its own .vhdx file, docker_data.vhdx. On a Mac, it keeps them in one disk image file, Docker.raw.
Where the disk files are
- WSL distribution from the Microsoft Store:
%LOCALAPPDATA%\Packages\<PackageFamilyName>\LocalState\ext4.vhdx - WSL distribution installed in another way: use the PowerShell command below to find its
ext4.vhdx - Docker Desktop on Windows:
%LOCALAPPDATA%\Docker\wsl\disk\docker_data.vhdx - Docker Desktop on a Mac:
~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
To get the exact path of one WSL distribution, Microsoft gives this PowerShell command. Replace <distribution-name> with a name from wsl -l -v:
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"What you can safely remove
| Path | What it is | Safe to delete | What happens if you delete it | How to clean it |
|---|---|---|---|---|
...\ | The whole file system of one WSL distribution | No | The distribution and every file, program and setting in it are lost | Delete files inside Linux, then compact the disk |
%LOCALAPPDATA%\ | Docker Desktop's images, containers, volumes and build cache | No | Docker loses every image, container and volume | docker system prune, then compact the disk |
~/ | The same Docker data on a Mac | No | Docker loses every image, container and volume | docker system prune, then check Docker Desktop settings |
stopped containers, unused networks, dangling images, build cache | What docker system prune removes | Yes | Stopped containers are gone; the rest comes back when needed | docker system prune |
images not used by a container | What docker system prune -a also removes | Careful | You pull or build those images again, which needs time and a network | docker system prune -a |
anonymous volumes not used by a container | What --volumes also removes | Careful | Data stored in those volumes, such as a test database, is lost | docker system prune --volumes |
wsl --unregister <name> | A whole WSL distribution you no longer need | Careful | All data, settings and software in it are lost for good | wsl --export a backup first, then wsl --unregister |
Step 1: free space inside Docker and Linux
Docker's docs say docker system prune removes "all stopped containers", "all networks not used by at least one container", "all dangling images" and "unused build cache". It asks before it deletes:
docker system pruneAdd -a to also remove every image that no container uses. Add --volumes to also remove anonymous volumes that no container uses. Volumes you named are not removed.
docker system prune -aIn a WSL distribution, delete what you do not need inside Linux; see which developer caches are safe to delete. This Microsoft command shows how full it is:
wsl.exe --system -d <distribution-name> df -h /mnt/wslg/distroStep 2: compact the disk on Windows
Compacting gives free space back to Windows and deletes no files inside Linux. Save your work and quit Docker Desktop first.
With diskpart (every Windows edition)
- Open PowerShell as administrator.
- Stop WSL. This ends every running distribution:
wsl --shutdown- Start
diskpartand run these lines one by one, with your own.vhdxpath:
diskpart
select vdisk file="C:\Users\you\AppData\Local\Packages\<PackageFamilyName>\LocalState\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exitMicrosoft's docs say you can only compact a disk that is "detached or attached as read-only".
With Optimize-VHD (Windows Pro or Enterprise with Hyper-V)
Optimize-VHD is in the Hyper-V module, and Hyper-V "can't be installed on Windows 10 Home or Windows 11 Home". In an administrator PowerShell window:
wsl --shutdown
Mount-VHD -Path "C:\path\to\ext4.vhdx" -ReadOnly
Optimize-VHD -Path "C:\path\to\ext4.vhdx" -Mode Full
Dismount-VHD -Path "C:\path\to\ext4.vhdx"Full mode needs the disk mounted read-only. The compact "can succeed without reducing the file size, if no optimization is possible".
The sparse VHD setting
In September 2023, Microsoft added a way to make a WSL disk shrink on its own:
wsl --manage <distro> --set-sparse trueLater WSL releases turned it off. On WSL 2.5.8, the command prints "Sparse VHD support is currently disabled due to potential data corruption" and asks for --allow-unsafe. WSL 3.0.2, a pre-release from October 2026, brings sparse disks back as an experimental feature. Run wsl --export first if you try it.
Docker Desktop on a Mac
On a Mac, Docker.raw is often one of the big items in what fills Mac storage. Run docker system prune first. Then open Docker Desktop, go to Settings > Resources > Advanced, and check two settings:
- Disk usage limit: "the maximum amount of disk space the engine can use". A lower limit caps how big the disk can grow.
- Disk image location: move the disk image to another disk if your startup disk is full.
Before you lower the limit a lot, back up the volumes you need.
How KemptDesk handles this
On a PC, Hidden space has a Linux disks (WSL) section with one card per distribution, its .vhdx path and its size. Compact disk opens an administrator PowerShell window that runs fstrim inside Linux, wsl --shutdown and a read-only diskpart compact vdisk.
Back up runs wsl --export. Remove runs wsl --unregister only after you type the name. Docker Desktop's distributions get a Docker Desktop tag and only Compact disk.
KemptDesk marks .vhdx files and Docker.raw as Breaks an app (red) and never selects them. It does not turn on sparse mode and does not run docker system prune. On a Mac, KemptDesk explains Docker.raw but does not compact it.
Questions
Why is ext4.vhdx so big after I deleted files?
The .vhdx file grows when Linux writes data, but it does not shrink when Linux deletes it. Compact it with diskpart or Optimize-VHD after wsl --shutdown to give the space back to Windows.
Can I delete ext4.vhdx?
Only if you accept losing the whole distribution. To remove a distribution on purpose, run wsl --export for a backup, then wsl --unregister; never delete the file while WSL knows about it.
What does docker system prune delete?
Stopped containers, networks no container uses, dangling images and unused build cache. With -a it also removes images no container uses; with --volumes it also removes anonymous volumes no container uses.
Sources
- How to manage WSL disk space (Microsoft Learn)
- Basic commands for WSL (Microsoft Learn)
- Advanced settings configuration in WSL: sparseVhd (Microsoft Learn)
- compact vdisk (Microsoft Learn)
- attach vdisk (Microsoft Learn)
- detach vdisk (Microsoft Learn)
- Optimize-VHD (Microsoft Learn)
- Mount-VHD (Microsoft Learn)
- Install Hyper-V (Microsoft Learn)
- Windows Subsystem for Linux September 2023 update (Microsoft Command Line blog)
- Sparse VHD support is currently disabled (microsoft/WSL issue 13075)
- Back up and restore Docker Desktop data (Docker Docs)
- docker system prune (Docker Docs)
- Docker Desktop settings: Resources > Advanced (Docker Docs)
- FAQs for Docker Desktop for Mac (Docker Docs)
- FAQs for Docker Desktop for Windows (Docker Docs)
- WSL 3.0.2 adds experimental sparse VHD creation (Phoronix)