Filter Docker Images List by Name

How to use Docker filter parameters

I recently started exploring Docker’s possibilities. I work a lot with Sitecore and the Sitecore community is setting up all kinds of different topologies from the Sitecore Experience Platform and converting Sitecore Experience Commerce to Docker configuration. The repository can be found at GitHub: https://github.com/Sitecore/docker-images.

Based on this repository a colleague of mine created a registry Azure and created all the images according to the definitions in this repository. With this repository it’s now super easy for me to start up a certain topology of Sitecore.

However, when creating the images something went wrong the first time. I therefore received an error message at the Sitecore Experience Commerce which prevented the containers from starting. After the images had been rebuilt, I wanted to start working with these fresh images. To do that, I wanted to discard all downloaded images from that specific topology and save the rest.

My first approach was to use a combination of Powershell and Docker commands. This function works fine:

docker images | Select-String -Pattern ".*-xc-.*"

However, the output is not a list of objects that can be manipulated and at the time I wanted to combine this commado with image deletion:

docker rmi $(docker images | Select-String -Pattern ".*-xc-.*")

I got the error message:

Error response from daemon: invalid reference format: repository name must be lowercase

So the combination of PowerShell syntax and Docker didn’t seem to work.

When reading the Docker documentation a bit better I noticed that there is a filter possibility for the images you want to show. However it took some time before I understood how syntax works. I missed the “reference” option.

My first attempt was:

docker images --filter=repository="*-xc-*"

Then I discovered the reference option. However, this didn’t work:

docker images --filter=reference="*-xc-*"

After a number of attempts, I understood that the following would work:

docker images --filter=reference="*/*-xc-*:*"

You have to include the registry and the name of the image and the tag as in your pattern separated by the slash (/) and colon (:)

Now it was easy to remove all images with a certain pattern:

docker rmi $(docker images --filter=reference="*/*-xc-*:*")

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s