DEV Community

Discussion on: How to reduce size of docker data volume in Docker Desktop for Windows v2

Collapse
 
zcahana profile image
Zvi Cahana • Edited

Thanks for this useful info!

Note that both Docker Desktop and WSL2 need to be stopped before running this, otherwise an error will occur:

Optimize-VHD : Failed to compact the virtual disk.
The system failed to compact 'C:\Users\ZVICAHANA\AppData\Local\Docker\wsl\data\ext4.vhdx'.
Failed to compact the virtual disk.
The system failed to compact 'C:\Users\ZVICAHANA\AppData\Local\Docker\wsl\data\ext4.vhdx': The process cannot access
the file because it is being used by another process. (0x80070020).
At line:1 char:1
+ Optimize-VHD -Path C:\Users\ZVICAHANA\AppData\Local\Docker\wsl\data\e ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceBusy: (:) [Optimize-VHD], VirtualizationException
    + FullyQualifiedErrorId : ObjectInUse,Microsoft.Vhd.PowerShell.Cmdlets.OptimizeVhd```




Enter fullscreen mode Exit fullscreen mode

To stop Docker Desktop, right click its tray icon and choose "Quit Docker Desktop".
To stop WSL2, open a command prompt and run wsl --shutdown.