Cleanup disk space occupied by Docker images
Solution 1
First try to run:
docker system prune
It will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all dangling images
If that's not enough, do:
docker system prune -a
It will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all images without at least one container associated to
If you haven't got what you expected, try the following
docker volume prune
It will remove all local volumes not used by at least one container.
Solution 2
Update Q4 2016: as I mention in "How to remove old and unused Docker images", use:
docker image prune -a
(more precise than docker system prune
)
It will remove dangling and unused images.
Warning: 'unused' means "images not referenced by any container": be careful before using -a
.
Then check if the disk space for images has shrunk accordingly.
Original answer:
See the Medium article "How to clean up Docker (~5GB junk!)" from katopz
.
It refers to the docker-cleanup
script, for removing old exited process, and dangling images.
I have my own aliases as well.
But it also mentions that, since docker 1.10, you now have named volumes that need to be removed as well:
docker volume rm $(docker volume ls -qf dangling=true)
Solution 3
To clean the system memory there are three steps:
- Delete docker image
- docker system prune -a
- quit the docker container app
This worked for me. Around 30gb of space was cleaned after doing the above mentioned steps.
vintrojan
Updated on July 14, 2022Comments
-
vintrojan almost 2 years
I am running docker on windows 10.
I had a couple of images stored in my machine. The total size of these images accumulated to around ~10GB. I have deleted these images via '
docker rmi -f
' command.But the space occupied by these images has not been released. If I run 'docker images' command, the deleted images are not listed in the output of 'docker images' command(but the disk space is not cleaned up).
How can I improve (ie. reduce) the disk space used by docker?
-
ilyas Jumadurdyew about 4 yearsIt's not working. Even if I don't have any images, containers or volumes at all, it still shows 64GB. System prune -a just shows "Total reclaimed space: 0 B". However ~/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2 is still 64GB. How?!
-
Artur Barseghyan about 4 yearsDo you perhaps have any containers running?
-
ilyas Jumadurdyew about 4 yearsNo only portainer and DB container (Db staus open, because after system prune I lose my custom network). I do really want to use containerization instead of virtualization. However uncontrollable oversizing is too big risk.
-
Artur Barseghyan about 4 yearsFor how long have you been using Docker? Did you try
docker volume prune
? -
ilyas Jumadurdyew about 4 yearsYes, I've tried all kinds of prune. The only solution is to Reset Docker. But is is not good since I loose all my settings, images, networks etc (Even working)
-
Kristaps J. about 4 years@ilyasJumadurdyew Try restarting docker. I also had issue that docker disk image didn't actually decrease in size even after prunes. So I just tried to restart docker itself, and it worked, all disk image is clear. (using windows)
-
Macindows over 3 yearsi cleared over 35 GB of junk! tnx, especially for the 2nd command.. dint see it elsewhere..
-
VonC over 3 years@Macindows Well done. since 2016, there is also
docker volume prune
that I mention in stackoverflow.com/a/32723127/6309, which could do the same. -
Surya Tej over 3 yearseven after docker restart, the memory occupeid is not cleared. I see several giga bytes of information being stored in
C:\ProgramData\docker\windowsfilter
folder -
jay about 3 yearsany solution yet? i am experiencing the same issues. images deleted but not the Hard disk space
-
Artur Barseghyan about 3 yearsDid you try
docker volume prune
? -
Dean almost 3 yearsDefinitely the quit docker and restart is needed to reclaim the space, at least on my Win10 box.