4

enter image description here

I've found that docker system df shows the large RECLAIMABLE space for me.
In order to save the space, I know that docker image prune -a will remove all unused images.
However, I'd like to know the list before pruning for the safety.
Is there any way to list all images those are currently not being used by any container? (The images that will be deleted by docker image prune -a)
I have searched for it but there are only pruning methods, no listing methods.

Kang San Lee
  • 312
  • 2
  • 10
  • 3
    pruning images should always be safe. If you are ever in a situation where you cant afford to delete an image, you did something wrong. There should be a Dockerfile for each of them or an upstream repositry. So you can always get your images back. – The Fool Apr 25 '22 at 08:00
  • You can see this post. @GPuri https://stackoverflow.com/questions/47414299/how-to-check-for-unuse-images-for-your-docker-containers – Michael H Apr 25 '22 at 08:32

2 Answers2

7

So to fetch all the unused docker images without actually pruning them, you could do the following

  1. Fetch all the images belonging to the running containers(which are not stopped or exited)

  2. Fetch all the images on the machine

  3. Then filter the images in step 1 from step 2

Below are the shell commands

runningImages=$(docker ps --format {{.Image}})
docker images --format "{{.ID}} {{.Repository}}:{{.Tag}}" | grep -v "$runningImages"
Tolis Gerodimos
  • 3,782
  • 2
  • 7
  • 14
0

you can use this command to show all of images:

docker images -a

You can find unused images using the command:

docker images -f dangling=true

and just a list of their IDs:

docker images -q -f dangling=true

In case you want to delete them:

docker rmi $(docker images -q -f dangling=true)