Filtering images works but not when using docker image prune

docker image ls --filter "label=testuseradd"
REPOSITORY                TAG       IMAGE ID       CREATED          SIZE
testuseradd/simple        example   74707eaff6fd   8 minutes ago    14.9MB
<none>                    <none>    00a050d211ee   12 minutes ago   14.9MB
testuseradd/custom_salt   example   8b3b4ca37de1   22 minutes ago   14.6MB
testuseradd               test      59af5882f846   23 hours ago     14.9MB

docker image prune --force --all --filter "label=testuseradd"
Total reclaimed space: 0B

docker image ls --filter "label=testuseradd"
REPOSITORY                TAG       IMAGE ID       CREATED          SIZE
testuseradd/simple        example   74707eaff6fd   13 minutes ago   14.9MB
<none>                    <none>    00a050d211ee   17 minutes ago   14.9MB
testuseradd/custom_salt   example   8b3b4ca37de1   27 minutes ago   14.6MB
testuseradd               test      59af5882f846   23 hours ago     14.9MB

docker image prune --force --all --filter "label=testuseradd"
Total reclaimed space: 0B

The images are filterable and found, but when docker image prune is forced to delete them, it does not find any.

Are you sure there are no stopped containers that use those images?

I just tried docker image prune --filter label=org.opencontainers.image.title on docker 20.10.14 to test if the basic prune and filter method has an issue. The command pruned orphaned images having that label.

As a further check I re-ran the command without the filter and it deleted all other orphaned images. At least for me the behavior is as expected.

Note: I didn’t use --all, as I have some unused images in the local cache I don’t want to loose.

1 Like

I was under the impression, it would force to delete them, even when there are stopped containers using those images.

It worked earlier with another filter, where I tested another image.

However, now that you mention it, I realise I did not run the image into a container the first time, now I do. So, now there are stopped containers.

Thank you very much, I think that was the problem. :+1:

Afaik --forceis just to suppress the confirmation dialog whether you want to delete the images or not.

1 Like

Just tested it. Works. I had misunderstood the force option.

Thank you!

P.S.:

I re-read the documentation.

--all , -a Remove all unused images, not just dangling ones

This was the line that caused me to think, that it does not matter if there are stopped containers associated with the to be pruned images. It in fact mentions, that it still only removes unused images. Okay, got it. I initially had skimmed it too quickly, it seems. :slightly_smiling_face: