Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleanup disk space occupied by Docker images

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?

like image 850
vintrojan Avatar asked May 30 '16 05:05

vintrojan


People also ask

How do you clean unused docker images?

If we do not want to find dangling images and remove them one by one, we can use the docker image prune command. This command removes all dangling images. If we also want to remove unused images, we can use the -a flag. The command will return the list of image IDs that were removed and the space that was freed.

How do I get rid of unused docker volumes?

Volumes are removed using the docker volume rm command. You can also use the docker volume prune command.

Is it safe to remove docker volumes?

Given you likely deleted the container long ago, the volumes are almost always safe to delete. You can run the following to delete anything with the long hash name. The deletes will fail if the volumes are currently in use, so there's no risk to running or even stopped containers.


2 Answers

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.

like image 69
Artur Barseghyan Avatar answered Oct 18 '22 18:10

Artur Barseghyan


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) 
like image 40
VonC Avatar answered Oct 18 '22 20:10

VonC