I committed an existing Docker container to create a new image but the committed image was way too large (the original image was 3+ GB, and with just a few additional things installed in the container, the committed image was 8+GB).
I'm low on space, so I decided to delete the committed image, but even after deleting the committed image, my disk space hasn't gone up. Yet, when I run docker system df
it's showing only the space that should be used original image and the container (I only have one image and one container).
Any way for me to free up the space that I'm sure is somehow still being occupied by that image I deleted? (For reference, I created the image, then deleted it, all within an hour, and was constantly monitoring my free space, so I'm pretty sure it's this and not something else that's taking up space.)
Also, I'm using Docker Desktop for Windows with WSL2 integration so it's not as easy to check Docker's disk use by just going to /var/lib/docker
and checking disk usage.
Nothing. It simply ran flawless from the exact state it was before having its image deleted.
Most of the space is occupied by docker volume as you can see from your output: Docker volumes are used to persist data for docker container and to share data between containers, and they are independent of the container’s lifecycle. So removing image/container will not free the disk space they occupied.
If your space is full in my experience docker prune will just hang. You need to manually delete the volumes. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.
Total reclaimed space: 6.749GB [docker]# du -sh . 2.7G . It's a kernel problem with devicemapper, which affects the RedHat family of OS (RedHat, Fedora, CentOS, and Amazon Linux). Deleted containers don't free up mapped disk space. This means that on the affected OSs you'll slowly run out of space as you start and restart containers.
A work-around of sorts is to give Docker its own volume to write to ( "When Docker eats up you disk space" ). This doesn't actually stop it from eating space, just from taking down other parts of your system after it does. My solution was to uninstall docker, then delete all its files, then reinstall:
I have used these commands to shrink desktop image from 35GB to 1GB
(in windows 10, docker version 19.03.13)
docker system prune -a
docker volume rm $(docker volume ls -q -f dangling=true)
Make sure HyperV turned on
%windir%\System32\mmc.exe "%windir%\System32\virtmgmt.msc"
or type Hyper-V in win search
Optimize disk in GUI > Go to VM, and check disk
Optimize-VHD -Path "C:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx" -Mode Full
Now I have 34+GB free disk space
You can purge data when you click on bug icon in header and then click clean / purge data..
Since you are on windows and running in docker for desktop your actually running docker in a VM. Then it depends what the disk image size is set to, usually virtual disks will expand to fill that space.
you can shrink a disk image though:
stop docker desktop
open an admin powershell terminal
run Optimize-VHD -Path "C:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx" -Mode Full
where the path is the path as documented in the docker desktop settings > Resources > Advanced > Disk image location.
start docker desktop
This should shrink the docker virtual machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With