透過壓縮Docker桌面WSL 2 VM回收大量磁碟空間 - Nick

banq發表於2022-01-06

需要以管理員身份開啟 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。

相關文章