How can I delete Docker images by tag, preferably with wildcarding?

I have some automated processes that spew a bunch of Docker images tagged with meaningful labels. The labels follow a structured pattern.

Is there a way to find and delete images by tag? So assume I have images:

REPOSITORY                  TAG
junk/root                   stuff_687805
junk/root                   stuff_384962

Ideally I'd like to be able to do: docker rmi -tag stuff_*

Any good way to simulate that?


Using only docker filtering:

 docker rmi $(docker images --filter=reference="*:stuff_*" -q)
  • reference="*:stuff_*" filter allows you to filter images using a wildcard;
  • -q option is for displaying only image IDs.

Update: Wildcards are matched like paths. That means if your image id is my-company/my-project/my-service:v123 then the * won't match it, but the */*/* will. See the github issue for description.


Fun with bash:

docker rmi $(docker images | grep stuff_ | tr -s ' ' | cut -d ' ' -f 3)