Does rebuilding with Docker Compose keep growing the WSL2 VHDX?

November 13, 2026 4 answers
Asked by Dapplet.9

I use Docker Desktop with WSL2 and run docker compose up --build frequently. My docker_data.vhdx has grown to around 90 GB, and pruning and compacting only seem to help temporarily.

Is that growth expected? Should I build less often, or is there a better way to manage the space?

Answers

v5+turnstile_318

The VHDX can grow as Docker stores images, build cache, containers, and other data. Running with --build doesn't necessarily add a full new image every time, though. Cached build steps can be reused, while changes can produce new cache entries and layers.

Check docker system df and docker system df -v to see what Docker reports before deciding what to remove. If you haven't changed anything that needs a rebuild, docker compose up without --build is a reasonable shortcut.

g503~txmode_8:

Those Docker figures describe Docker's data, not necessarily the physical size of the VHDX. Deleting data inside it doesn't always shrink the file on Windows by itself.

Reply to this answer
!leave+the~staples

Pruning and compacting are two separate jobs. Pruning removes eligible Docker data, while compaction tries to return unused space in the virtual disk to Windows. The file can grow again as that space is used later.

Optimize-VHD is another compaction option if it's available on your Windows setup. Shut down WSL before working on the disk, and make sure you're targeting the right VHDX. Compaction won't fix continued accumulation of data that Docker still considers in use.

Reply to this answer
p4~saucer_718

Installing Docker directly inside WSL instead of using Docker Desktop is an option, but I wouldn't expect that alone to solve the disk growth. WSL distributions also use VHDX files, so you'd still have storage and compaction to manage.

Reply to this answer
z86~port_31

Some growth is normal, and it isn't automatically a problem if you have plenty of space. Still, 90 GB is worth investigating rather than assuming it's all necessary. Prune selectively when cache is taking up space you need, but remember that removing build cache can make later builds slower.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions