Docker Diagnosis
August 8, 2024Less than 1 minute
Reduce Docker File Size
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.
Please reclaim some space on windows following the steps below:
Step 1: Release the file from the ocupied process
net stop com.docker.service
taskkill /IM "docker.exe" /F
taskkill /IM "Docker Desktop.exe" /F
wsl --shutdown
Step 2: Reclaim the space
(Please using PowerShell)
Optimize-VHD -Path $Env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx -Mode Full
Optimize-VHD -Path $Env:LOCALAPPDATA\Docker\wsl\disk\docker_data.vhdx -Mode Full