Blog · Sleepless Coder
Cleaning disk space after docker
Using docker on your computer, you can notice how actively it uses space for containers and images. Sooner or later, the moment comes when it’s time to clean the whole place.
If you are using linux, then you have no problems, just use the command:
docker system prune
But it doesn’t work on windows, why? The problem is that docker stores all its data inside a virtual disk.vhdx which can grow independently, but not decrease in size. But it doesn’t matter, because there is a way to manually compress it.
To begin with, let’s decide on the windows edition, because the decision depends on it.
If you have Windows Home Edition
- Open the PowerShell window as an administrator
- Determine where the docker disk file is located
By default, it is stored on the path
"C:\Users\User\AppData\Local\Docker\wsl\data\ext4.vhdx " - Shut down Windows Subsystem for Linux with the command
wsl --shutdown
- Run the DiskPart utility
diskpart
- Select the file with the docker disk
select vdisk file="C:\Users\User\AppData\Local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
- Perform compression, it may take quite a long time, depending on the weight of the file
compact vdisk
- Shut down the DiskPart utility
detach vdisk
exit
If you don’t have Windows Home Edition
- Open the PowerShell window as an administrator
- Connect the Hyper-V module in PowerShell
Import-Module Hyper-V
- Determine where the docker disk file is located
By default, it is stored on the path
"C:\Users\User\AppData\Local\Docker\wsl\data\ext4.vhdx " - Shut down Windows Subsystem for Linux with the command
wsl --shutdown
- Go to the directory with the disk
cd "C:\Users\User\AppData\Local\Docker\wsl\data \"
- Perform compression, it may take quite a long time, depending on the weight of the file
optimize-vhd -Path .\ext4.vhdx -Mode full
Just like that, we freed up a couple (dozens) gigabytes on our disk.
Keep reading
Related articles
Reducing lxc size in Proxmox
Sometimes there comes a moment when a container in Proxmox becomes uselessly large and its size nee
ArticleMigrating a PostgreSQL Database Using Replication
Today we will talk about how to migrate a production PostgreSQL database without any downtime for o
ArticleDHC-6-400 Crash in Nepal 2016
The DHC 6 plane crash occurred on February 24, 2016 in Nepal, near the village of Dana. Of the 23 p