Docker WSL: Disk Cleanup & Optimization

Docker Desktop on Windows uses WSL2 with dynamic VHDX files. They grow when adding images/containers but don’t shrink automatically when deleting them. Result: C: drive fills up, even though docker system df shows free space. 💡 Solution: manual VHDX optimization via PowerShell + Docker utility. 📦 Cleanup script Create file # File: $HOME\Scripts\docker-clear-wsl.ps1 $script = @' $LOCAL = "$env:LOCALAPPDATA\Docker\wsl" $VHD1 = Join-Path $LOCAL "disk\docker_data.vhdx" $VHD2 = Join-Path $LOCAL "main\ext4.vhdx" # 1. Docker cleanup docker system prune -f # 2. Reclaim space via official tool docker run --rm --privileged --pid=host docker/desktop-reclaim-space docker rmi docker/desktop-reclaim-space -f # 3. Stop Docker Desktop Get-Process -Name "Docker Desktop","com.docker.backend","com.docker.build" ` -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue # 4. Shutdown WSL wsl --shutdown # 5. Optimize VHDX files (compact) if (Test-Path $VHD1) { Optimize-VHD -Path $VHD1 -Mode Full } if (Test-Path $VHD2) { Optimize-VHD -Path $VHD2 -Mode Full } # 6. Restart Docker Desktop Start-Sleep -Seconds 2 Start-Process -FilePath "$env:ProgramFiles\Docker\Docker\Docker Desktop.exe" ` -ErrorAction SilentlyContinue '@ $script | Out-File -FilePath "$HOME\Scripts\docker-clear-wsl.ps1" -Encoding UTF8 Run # As Administrator (required for Optimize-VHD) powershell.exe -ExecutionPolicy Bypass -File "$HOME\Scripts\docker-clear-wsl.ps1" 🔍 How it works Step Command What it does 1 docker system prune -f Removes stopped containers, unused images, build cache 2 docker/desktop-reclaim-space Official Docker tool to reclaim space in WSL2 3 Stop-Process Gracefully stops Docker Desktop (otherwise VHDX is locked) 4 wsl --shutdown Fully shuts down WSL, freeing files for optimization 5 Optimize-VHD -Mode Full Compacts VHDX files, returning space to host 6 Start-Process Restarts Docker Desktop Why this way: ...

17 Mar 2026 · 3 min · 614 words · Potato Energy Team, ponfertato

WSL2: Developer's Complete Guide

WSL (Windows Subsystem for Linux) lets you run native Linux command-line tools directly on Windows - no VM, no dual boot. WSL1 - syscall translation layer (fast, but not 100% compatible) WSL2 - real Linux kernel in lightweight virtualization (full compatibility, slightly more resources) 💡 Use WSL2. Near-native performance with full Docker, systemd, and Linux feature support. Requirements OS: Windows 10 (2004+, build 19041+) or Windows 11 Architecture: x64 or ARM64 Privileges: Administrator (for install) Virtualization: Enabled in BIOS/UEFI (Hyper-V Platform) Check virtualization: ...

16 Mar 2026 · 4 min · 822 words · Potato Energy Team, ponfertato