Filtering docker images by pattern with wildcards

Igor Kliushnikov
2 min readSep 8, 2019
Jack Sparrow knows how to find desired artifacts

Likely, if you work with docker containers on a regular basis, your local image cache might be full of more or less important possessions and finding the right set of images might be tricky.

To list docker images we can use docker image list command or a shorter version of it docker images. To filter the result of this output there is an argument--filter. A lot of details and examples are in the official doc: filter by a label, by date, by a pattern, and others

The pattern option supports the wildcard character *, which is barely documented, only a few examples:

Official Docker filtering documentation

What is not documented — you can avoid --filter=reference keyword and just type docker images “example.com/*”:

REPOSITORY       TAG       IMAGE ID         CREATED        SIZE
example.com/baz latest 43773d1dba76 3 months ago 4.03MB
example.com/bar latest d8233ab899d4 3 months ago 1.2MB

But what is not obvious for me and docs also do not say it: the wildcard character does not apply to / in repository name.

In our company case, we extensively use repository names following the pattern mycontainerregistry.azurecr.io/{moduleName}/{applicationName} and to filter all our custom images I have to use docker images “mycontainerregistry.azurecr.io/*/*, not just“mycontainer.azurecr.io/* or “mycontainerregistry.azurecr.io/**:

I spent some time figuring out why my simple wildcard notation was not working, so I hope I would save someone’s time ;)

--

--

Igor Kliushnikov

I’m writing some code occasionally, you can check it out at my github: https://github.com/v1r7u. Interested in Clouds, Kubernetes, DevOps