通过压缩Docker桌面WSL 2 VM回收大量磁盘空间 - Nick


需要以管理员身份打开 PowerShell,然后运行以下命令:

# Close all WSL terminals and run this to fully shut down WSL.
wsl.exe --shutdown

# Replace Nick with your Windows user name. This is where Docker stores its VM file.
cd C:\Users\Nick\AppData\Local\Docker\wsl\data

# Compact the Docker Desktop WSL VM file and you're done.
# NOTE: This may not work with Windows Home edition (read below).
optimize-vhd -Path .\ext4.vhdx -Mode full

如果您使用的是 Windows 家庭版并且optimize-vhd不是有效命令,您可以尝试运行以下命令:

# Replace Nick with your Windows user name.
diskpart
select vdisk file="C:\Users\Nick\AppData\local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk

所有内容都适用于所有版本的 Windows 10。