42

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?

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
vintrojan
  • 1,037
  • 1
  • 11
  • 20
  • 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

5 Answers5

49

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
  • 10,830
  • 4
  • 48
  • 39
  • 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
13

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,129,465
  • 480
  • 4,036
  • 4,755
  • 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
4

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
  • 26,923
  • 21
  • 73
  • 125
Anmol Narang
  • 472
  • 4
  • 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
0

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

Binita Bharati
  • 4,026
  • 1
  • 34
  • 22
0

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

user959690
  • 564
  • 8
  • 16