Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recall704/3b8153c3cd58bf1594964eeec01d78cd to your computer and use it in GitHub Desktop.
Save recall704/3b8153c3cd58bf1594964eeec01d78cd 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