High Disk Usage in Docker on Windows
an easy way to reclaim the huge disk space used by docker on windows
Introduction
When installing Docker Desktop on Windows, a common issue that can arise is the failure of Docker to release disk space back to the operating system. To resolve this, additional steps are required to reclaim the disk usage in WSL
.
1- Clean the Docker
First, you need to delete unused Docker images and stopped containers using the following command:
C:\> docker system prune -a
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 20.38GB
2- Reclaim WSL disk usage
After running the above command, the disk usage is still not reduced! To reclaim the disk space used by WSL
to the OS, you need to run the following commands in the CMD
window:
C:\> wsl --shutdown
C:\> diskpart
In the DISKPART
terminal, you have to enter the following commands (replace ${YOUR_USERNAME}
with your username in the bellow command):
DISKPART> select vdisk file="C:\Users\${YOUR_USERNAME}\AppData\Local\Docker\wsl\data\ext4.vhdx"
DISKPART> attach vdisk readonly
DISKPART> compact vdisk
DISKPART> detach vdisk
DISKPART> exit
Feedback
If you have any feedback or suggestions for improving my code, please leave a comment on this post or send me a message on my Linkedin page: https://www.linkedin.com/in/mahdi-mallaki-1aa9b083. I would greatly appreciate your contributions to help make this article better. If you enjoyed this post, be sure to follow me to stay updated on my latest articles.