66

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?

Lee Goddard
  • 10,680
  • 4
  • 46
  • 63
vintrojan
  • 1,277
  • 1
  • 12
  • 22
  • 1
    Possible duplicate of [How to remove old and unused Docker images](https://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images) – kenorb Apr 13 '18 at 00:27

8 Answers8

88

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.

Artur Barseghyan
  • 12,746
  • 4
  • 52
  • 44
  • 3
    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?! – ilyas Jumadurdyew Apr 13 '20 at 18:13
  • Do you perhaps have any containers running? – Artur Barseghyan Apr 14 '20 at 08:23
  • 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. – ilyas Jumadurdyew Apr 20 '20 at 21:53
  • For how long have you been using Docker? Did you try `docker volume prune`? – Artur Barseghyan Apr 23 '20 at 07:49
  • 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) – ilyas Jumadurdyew Apr 23 '20 at 08:41
  • @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) – Kristaps J. Apr 25 '20 at 08:24
  • 1
    even after docker restart, the memory occupeid is not cleared. I see several giga bytes of information being stored in `C:\ProgramData\docker\windowsfilter` folder – Surya Tej Oct 28 '20 at 07:41
  • any solution yet? i am experiencing the same issues. images deleted but not the Hard disk space – jay Mar 21 '21 at 09:22
  • Did you try `docker volume prune`? – Artur Barseghyan Mar 21 '21 at 22:25
19

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)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • i cleared over 35 GB of junk! tnx, especially for the 2nd command.. dint see it elsewhere.. – Macindows Oct 07 '20 at 11:35
  • @Macindows Well done. since 2016, there is also `docker volume prune` that I mention in https://stackoverflow.com/a/32723127/6309, which could do the same. – VonC Oct 07 '20 at 11:38
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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Anmol Narang
  • 532
  • 5
  • 10
  • Definitely the quit docker and restart is needed to reclaim the space, at least on my Win10 box. – Dean Jun 01 '21 at 19:41
5

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.

ns15
  • 5,604
  • 47
  • 51
  • 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!!! – Frederik Nielsen Apr 11 '23 at 07:29
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%.

Nick
  • 9,735
  • 7
  • 59
  • 89
1

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

user959690
  • 602
  • 9
  • 16
1

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.

Lee Goddard
  • 10,680
  • 4
  • 46
  • 63
0

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

Binita Bharati
  • 5,239
  • 1
  • 43
  • 24