简体   繁体   中英

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?

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.

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)

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.

On windows with docker desktop running on wsl2 there is an option in GUI to purge data. 在此处输入图像描述

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.

docker system prune在我运行Ubuntu 2020.10.2机器上完美运行。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM