The problem of WSL2 disk space not being released after deleting the container in Windows Docker

HBLOG
CodeX
Published in
3 min read2 days ago

1. Causes and reasons

Many students found that the C drive was almost full after using the image for a period of time. They deleted the previously used images and containers and found that the size of the virtual disk in the WSL mount directory did not change, which was very strange. In fact, unlike WSL1, WSL2 is essentially a virtual machine , so Windows will automatically create a virtual disk file with the vhdx suffix as storage. The virtual disk file with the vhdx suffix is ​​characterized by automatic expansion, but generally not automatic reduction . Once there are many files that “expand” it, it will not automatically “shrink” even if these files are deleted. Therefore, after deleting the files, we still need to manually compress them to free up disk space.

2. Solution

2.1 Find the virtual disk file to be compressed

If you did not change the location of the mounted disk, then its location is here C:\Users\{username}\AppData\Local\Docker\wsl\data\ext4.vhdx . Note the path as it will be needed later.

2.2 Close Docker Desktop

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

HBLOG

Written by HBLOG

talk is cheap ,show me your code

No responses yet

What are your thoughts?