How to Completely Shrink the Docker Desktop Data Disk on Windows
This guide explains how to reduce the size of the Docker Desktop data disk on Windows when Docker is using the WSL 2 backend.
Docker Desktop stores its Linux filesystem inside a virtual hard disk file, usually called:
ext4.vhdxThe file can become very large over time because Docker images, containers, volumes, build cache, and deleted files may leave unused space inside the virtual disk.
Important: There are two different things involved:
- Free space inside the Docker Linux filesystem.
- The physical size of the
ext4.vhdxfile on Windows.Running
docker system pruneonly frees space inside Docker. To reduce the actual.vhdxfile on Windows, the virtual disk must also be compacted.
1. Check the Current Size
First, check how large the Docker data disk is.
The file is commonly located somewhere similar to:
%LOCALAPPDATA%\Docker\wsl\disk\ext4.vhdxYou can open the directory with:
explorer "$env:LOCALAPPDATA\Docker\wsl\disk"You should see something similar to:
ext4.vhdxCheck its size:
Get-Item "$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx" |
Select-Object Name, LengthTo display the size in GB:
$disk = Get-Item "$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx"
"{0:N2} GB" -f ($disk.Length / 1GB)2. Clean Up Docker
Before compacting the virtual disk, remove everything that Docker no longer needs.
Warning: The following commands can delete unused Docker resources. Make sure you do not need unused images, stopped containers, networks, or volumes before proceeding.
Start with:
docker system dfThis shows how much space Docker is currently using.
Example:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 20 3 15GB 10GB
Containers 10 2 2GB 1GB
Local Volumes 15 5 20GB 12GB
Build Cache ... ... ...3. Remove Unused Docker Resources
Remove stopped containers
docker container pruneRemove unused networks
docker network pruneRemove unused images
To remove dangling images:
docker image pruneTo remove all images that are not currently used by a container:
docker image prune -aRemove unused volumes
Be careful with this command:
docker volume pruneVolumes can contain important application data.
Only remove them if you are certain that the data is no longer required.
4. Clean Everything at Once
If you are certain that all unused Docker resources can be deleted, you can use:
docker system prune -a --volumesThis removes:
- stopped containers
- unused networks
- unused images
- build cache
- unused volumes
Docker will ask for confirmation.
WARNING! This will remove:
...
Are you sure you want to continue? [y/N]Enter:
yAfterwards, check the result:
docker system df5. Stop Docker Desktop Completely
Docker must not be using the virtual disk while it is being compacted.
First quit Docker Desktop.
You can do this from the Docker Desktop tray icon:
Docker Desktop
-> Quit Docker DesktopThen make sure Docker Desktop is no longer running.
You can also check:
Get-Process *docker* -ErrorAction SilentlyContinueIdeally, no Docker Desktop processes should still be running.
6. Shut Down WSL Completely
Even after Docker Desktop has been closed, WSL may still have running distributions.
Run:
wsl --shutdownThis shuts down all running WSL 2 instances.
You can verify the state with:
wsl --list --verboseThe distributions should not be running.
For example:
NAME STATE VERSION
* docker-desktop Stopped 27. Make a Backup of ext4.vhdx
Before modifying the virtual disk, create a backup.
For example:
Copy-Item `
"$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx" `
"$env:USERPROFILE\Desktop\ext4-docker-backup.vhdx"Depending on the size of the Docker disk, this can take a while.
Do not continue until the copy has completed successfully.
8. Compact the VHDX
There are multiple ways to compact the Docker VHDX.
The preferred Windows tool is diskpart.
Open PowerShell or Command Prompt as Administrator.
Start DiskPart:
diskpartYou should see:
Microsoft DiskPart version ...
DISKPART>9. Select the Docker VHDX
Inside DiskPart, use:
select vdisk file="C:\Users\<USERNAME>\AppData\Local\Docker\wsl\disk\ext4.vhdx"Replace:
<USERNAME>with your Windows username.
For example:
select vdisk file="C:\Users\John\AppData\Local\Docker\wsl\disk\ext4.vhdx"If your Windows installation is on another drive, use the corresponding path.
10. Compact the Virtual Disk
Once the VHDX has been selected, run:
compact vdiskDiskPart should report something similar to:
100 percent completed
DiskPart successfully compacted the virtual disk file.Then exit:
exit11. Check the Result
Check the file size again:
$disk = Get-Item "$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx"
"{0:N2} GB" -f ($disk.Length / 1GB)You can also check it in Explorer:
explorer "$env:LOCALAPPDATA\Docker\wsl\disk"For example, before cleanup:
ext4.vhdx
Size: 80 GBAfter cleanup and compaction:
ext4.vhdx
Size: 25 GBThe exact result depends on how much data was actually removed.
12. Start Docker Desktop Again
Start Docker Desktop normally.
Wait until Docker reports that it is running.
Then test:
docker versionAnd:
docker psYour containers, images, and volumes that were not removed should still be available.
13. Verify Docker Storage
Run:
docker system dfThis lets you verify how much Docker is actually using.
You can also check the VHDX again:
$disk = Get-Item "$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx"
"{0:N2} GB" -f ($disk.Length / 1GB)14. Optional: Check the VHDX Before and After
A convenient way to document the result is:
$disk = Get-Item "$env:LOCALAPPDATA\Docker\wsl\disk\ext4.vhdx"
[PSCustomObject]@{
File = $disk.FullName
SizeGB = [math]::Round($disk.Length / 1GB, 2)
}Example output:
File SizeGB
---- ------
C:\Users\John\AppData\Local\Docker\wsl\disk\ext4.vhdx 24.7315. Complete Procedure
If you want the process as a short checklist:
1. Check current ext4.vhdx size
2. Check Docker storage
3. Remove unused Docker resources
4. Quit Docker Desktop
5. Run: wsl --shutdown
6. Back up ext4.vhdx
7. Start DiskPart as Administrator
8. select vdisk file="...\ext4.vhdx"
9. compact vdisk
10. exit
11. Start Docker Desktop
12. Verify Docker
13. Check the new ext4.vhdx size16. Recommended Commands
The complete command sequence is approximately:
# Check Docker usage
docker system df
# Optional cleanup
docker system prune -a --volumes
# Shut down WSL
wsl --shutdownThen, from an Administrator PowerShell/CMD:
diskpartInside DiskPart:
select vdisk file="C:\Users\<USERNAME>\AppData\Local\Docker\wsl\disk\ext4.vhdx"
compact vdisk
exitThen start Docker Desktop again.
17. Important: docker system prune Is Not Enough
A common misconception is that:
docker system prune -a --volumeswill automatically make the ext4.vhdx file smaller.
It usually does not.
For example:
Before cleanup:
ext4.vhdx = 100 GB
Docker uses:
30 GB
Unused space:
70 GBAfter Docker cleanup:
Docker uses:
30 GB
Unused space:
70 GB
ext4.vhdx:
still approximately 100 GBAfter compacting the VHDX:
Docker uses:
30 GB
ext4.vhdx:
approximately 30–40 GBThe exact size depends on the filesystem layout and how much unused space can be reclaimed.
18. If compact vdisk Does Not Reduce the Size
If compact vdisk reports success but the file barely gets smaller, there may still be allocated blocks inside the Linux filesystem.
In that situation, first make sure Docker resources have actually been removed:
docker system dfThen shut everything down again:
wsl --shutdownAfter that, retry:
diskpart
select vdisk file="C:\Users\<USERNAME>\AppData\Local\Docker\wsl\disk\ext4.vhdx"
compact vdisk
exitIf the VHDX still does not shrink sufficiently, an additional filesystem-level optimization may be necessary.
19. Important Difference: Dynamic VHDX vs. Maximum Size
The ext4.vhdx file is normally a dynamically expanding virtual disk.
This means:
Virtual disk capacity
!=
Physical file sizeFor example:
Virtual capacity: 1 TB
Physical file size: 40 GBdoes not mean that 1 TB is actually consuming 1 TB on your Windows drive.
The important value for Windows disk usage is the physical file size.
20. Do Not Delete ext4.vhdx Manually
Do not simply delete:
ext4.vhdxunless you intentionally want to destroy the Docker Desktop WSL data.
Deleting the file can remove:
- Docker images
- Docker containers
- Docker volumes
- container filesystem data
- Docker build cache
- other Docker Desktop data
If you only want to reclaim disk space, use cleanup + VHDX compaction instead.
21. Recommended Safe Workflow
For production or otherwise important Docker environments, use this workflow:
┌─────────────────────┐
│ Check Docker usage │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Backup important │
│ Docker volumes/data │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Remove unused Docker │
│ resources │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Quit Docker Desktop │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ wsl --shutdown │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Compact ext4.vhdx │
│ with DiskPart │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Start Docker │
│ Desktop again │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Verify containers │
│ and volumes │
└─────────────────────┘22. One-Liner to Find the Docker VHDX
If you are unsure where the Docker VHDX is located, try:
Get-ChildItem "$env:LOCALAPPDATA\Docker" -Filter *.vhdx -Recurse -ErrorAction SilentlyContinue |
Select-Object FullName, LengthThis searches the Docker directory for VHDX files.
23. Final Notes
The safest general approach is:
Docker cleanup
↓
Docker Desktop shutdown
↓
WSL shutdown
↓
VHDX backup
↓
DiskPart compact
↓
Docker Desktop restart
↓
Verification