Skip to content

Docker's disk on Windows is a WSL virtual disk that only grows

Images, volumes and build cache inside a vhdx that never shrinks by itself. The prune order and the compaction step.

6 min read

Docker Desktop on Windows stores everything inside a virtual disk managed by WSL. That file grows as you build and never shrinks on its own, so pruning inside Docker frees space inside the file rather than on your drive.

Finding the disk

Get-ChildItem "$env:LOCALAPPDATA\Docker\wsl" -Recurse -Filter *.vhdx -EA SilentlyContinue |
  Select-Object @{n='GB';e={[math]::Round($_.Length/1GB,2)}}, FullName
docker system df

docker system df reports images, containers, volumes and build cache with a reclaimable figure for each. Read that before pruning anything, because it separates what is genuinely unused from what a running container needs.

What each prune removes

CommandRemovesRisk
docker builder pruneBuild cacheNone. Rebuilds are slower
docker image prune -aImages no container usesRedownload or rebuild
docker container pruneStopped containersAnything written inside them
docker volume pruneVolumes nothing referencesData. This is the dangerous one
docker system prune -a --volumesAll of the aboveEverything above at once

Then reclaim the disk

After pruning, the vhdx is still the size it was. Docker Desktop has a Disk usage view with a Reclaim space action, and recent versions can do it automatically. The manual route is to shut WSL down and compact the disk, which is the same procedure as any WSL distribution:

wsl --shutdown
# then compact, either through Docker Desktop's own setting
# or with diskpart's compact vdisk on the vhdx

The habit that keeps it small

  • Run docker builder prune weekly, filtered by age. Build cache grows fastest and is safest to remove.
  • Use docker image prune -a after finishing a project, not during one.
  • Name your volumes, so docker volume ls is readable when it comes to pruning.
  • Check docker system df before assuming Docker is the problem.

Common questions

Why does pruning Docker not free space on Windows?

Because everything lives inside a WSL virtual disk that only grows. Pruning frees space inside that file, and the file has to be compacted separately before Windows sees it.

Where is Docker's disk on Windows?

Under %LOCALAPPDATA%\Docker\wsl as a .vhdx file. Docker Desktop's Disk usage view shows its size and offers a reclaim action.

What is the difference between docker system prune and prune with volumes?

Without the volumes flag it removes stopped containers, unused networks, dangling images and build cache, all rebuildable. Adding --volumes also removes volumes nothing references, and those hold real data.

How do I shrink the Docker vhdx?

Prune inside Docker first, then use Docker Desktop's reclaim space action, or shut WSL down and compact the disk with diskpart.

Read next