How can I reduce the disk space used by docker?
Asked Answered
C

9

82

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?

Clockmaker answered 30/5, 2016 at 5:22 Comment(3)
Possible duplicate of How to remove old and unused Docker imagesAnimate
Not a duplicate, because docker consumes disk space for other stuff too. For example build cache, which might take up a lot of space. Check @xab answer below.Pasargadae
For Docker on Windows / WSL, see also: #70946640Militiaman
C
112

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.

Consistence answered 1/11, 2018 at 9:8 Comment(9)
It'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?!Gabby
Do you perhaps have any containers running?Consistence
No 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.Gabby
For how long have you been using Docker? Did you try docker volume prune?Consistence
Yes, 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)Gabby
@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)Jandy
even after docker restart, the memory occupeid is not cleared. I see several giga bytes of information being stored in C:\ProgramData\docker\windowsfilter folderSeep
any solution yet? i am experiencing the same issues. images deleted but not the Hard disk spaceYokoyama
Did you try docker volume prune?Consistence
K
22

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)
Kneel answered 30/5, 2016 at 6:29 Comment(2)
i cleared over 35 GB of junk! tnx, especially for the 2nd command.. dint see it elsewhere..Musketry
@Musketry Well done. since 2016, there is also docker volume prune that I mention in https://mcmap.net/q/45639/-how-to-remove-old-and-unused-docker-images, which could do the same.Kneel
E
8

On windows with docker desktop running on wsl2 there is an option in GUI to purge data. enter image description here

select wsl2 when prompted for data store.

Note: This option will remove all of your docker data. If you don't wish to do so then try the prune option mentioned by others in this thread.

Eminence answered 27/7, 2022 at 11:31 Comment(2)
After doing all commands people suggested in here, and it the CMD told me it had free 55GB of data. It only had removed like 3GB, after running this in docker desktop I got 91GB space back. THANKS!!!Isochroous
I did the same. Got 200GB back, and the other commands weren't nearly as effective!Misteach
S
6

First to find out what is using the space:
docker system df see docs

In my case most of it was used by "Build cache", to remove it:
docker builder prune see docs

Specialist answered 27/10, 2023 at 7:37 Comment(1)
seccond command deleted 1 year of cache - about 80 gb which was untouched by docker image / volume etc pruneEmbrocation
N
5

To clean the system memory there are three steps:

  1. Delete docker image
  2. docker system prune -a
  3. quit the docker container app

This worked for me. Around 30gb of space was cleaned after doing the above mentioned steps.

Navicular answered 9/11, 2020 at 13:51 Comment(1)
Definitely the quit docker and restart is needed to reclaim the space, at least on my Win10 box.Nova
B
4

In addition to the use of docker prune -a, be aware of this issue: Windows 10: Docker does not release disk space after deleting all images and containers #244.

It is a frighteningly long and complicated bug report that has been open since 2016 and has yet to be resolved, but might be addressed through the "Troubleshoot" screen's "Clean/Purge Data" function:

enter image description here

enter image description here

I have just used this to re-claim 100 gig.

WARNING: This of course deletes all the data concerned.

Bluepencil answered 9/2, 2023 at 7:31 Comment(1)
Warning: THIS COMPLETELY REMOVES ALL OF YOUR DATA - all containers, volumes, etc. Make sure you don't need any of these before pruning it.Inadvisable
M
2

If your space is full in my experience docker prune will just hang. You need to manually delete the volumes.

Madalinemadalyn answered 17/7, 2021 at 18:21 Comment(0)
S
2

My disk was used 80%, but a calculation of file sizes on the disk showed about 10% of usage.

In my case cleaning docker caches, volumes, images, and logs not helped. But helped restart of docker service:

sudo systemctl restart docker

After this usage of the disk has become equal to the expected 10%.

Stringed answered 20/10, 2022 at 15:56 Comment(0)
D
0

docker system prune works perfectly on my machine running Ubuntu 20 and docker 20.10.2.

Duster answered 18/2, 2021 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.