Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjmartres/177c68d3f44a4f8a82d9d0bc42a97637 to your computer and use it in GitHub Desktop.
Save jjmartres/177c68d3f44a4f8a82d9d0bc42a97637 to your computer and use it in GitHub Desktop.
How to reduce size of docker data volume in Docker Desktop for Windows v2

How to reduce size of docker data volume in Docker Desktop for Windows v2

Docker Desktop for Windows v2, which uses WSL2, stores all image and container files in a separate virtual volume (vhdx). This virtual hard disk file can automatically grow when it needs more space (to a certain limit). Unfortunately, if you reclaim some space, i.e. by removing unused images, vhdx doesn't shrink automatically.

Optimize

wsl --shutdown
Optimize-VHD -Path "$($env:LOCALAPPDATA)\Docker\wsl\data\ext4.vhdx" -Mode Full

Resize

Set-Variable -Name "MaxSizeGB" -Value "32GB"
wsl --shutdown
resize-vhd -Path "$($env:LOCALAPPDATA)\Docker\wsl\data\ext4.vhdx" -SizeBytes $MaxSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment