Skip to content

Instantly share code, notes, and snippets.

@automata
Last active May 21, 2024 13:24
Show Gist options
  • Save automata/1af2b10d1166cc1865abed899f79f0f1 to your computer and use it in GitHub Desktop.
Save automata/1af2b10d1166cc1865abed899f79f0f1 to your computer and use it in GitHub Desktop.
Freeing space from Docker on Windows WSL
# Freeing space from Docker on Windows WSL
# (No need for HyperV and optimize-vhd: works on Windows Home Edition)
# Make sure to keep the images you really need running on Docker, this way the following command will
# only delete the cached layers:
# On WSL:
docker system prune -a
# On PowerShell:
wsl --manage Ubuntu -s false
wsl --manage docker-desktop-data -s false
wsl --manage docker-desktop -s false
wsl --list --verbose
wsl --shutdown
diskpart
# On Diskpart:
select vdisk file="C:\Users\<YourUser>\AppData\Local\Docker\wsl\data\ext4.vhdx"
compact vdisk
detach vdisk
select vdisk file="C:\Users\<YourUser>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx"
compact vdisk
detach vdisk
exit
# Back on WSL:
wsl --manage Ubuntu -s true
wsl --manage docker-desktop-data -s true
wsl --manage docker-desktop -s true
@automata
Copy link
Author

The secret is to also free the one in Docker app data, not only the Ubuntu one...

@automata
Copy link
Author

Also, WinDirStat is a pretty awesome GPL app: https://windirstat.net/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment