Docker

How to Filter Docker Images by Pattern With Wildcards

While working on Docker, developers deal with various Docker images. However, when there are a large number of Docker images, it can be difficult and time-consuming to identify specific images based on their exact names or tags. In this situation, wildcards can be used that allow users to specify a pattern that matches a group of images based on a partial name or tag, or other attributes. This can save time and effort when users need to filter images based on a specific criterion.

This article will explain the method to filter Docker images by pattern using wildcards.

How to Filter Docker Images by Pattern Using Wildcards?

Wildcards are special characters that can be utilized to match any other character or sequence of characters in a string. To filter Docker images by pattern with wildcards, first, view all the Docker images. Then, utilize the “docker images “<wildcard-pattern>”” command. The, “<wildcard-pattern>” can be a partial or full image name or tag, and a wildcard character “*” is used to match any characters before or after the pattern.

Step 1: List All Docker Images

First, display all the available Docker images via the below-listed command:

docker images

In the above output, all the Docker images can be seen.

Step 2: Filter Docker Images

To filter images and list only those whose name starts with “img”, utilize the “docker images “img*”” command:

docker images "img*"

The above output has returned the list of the images whose names are starting with “img”.

To display images that end with the word “img”, use “*” before the keyword:

docker images "*img"

This command has displayed one image which is ending with the “img” word.

Moreover, use the “*” symbol at the start and end of the keyword to list all the images that contain the particular keyword in them:

docker images "*img*"

The above screenshot shows the list of all Docker images whose names contain the word “img”.

To filter a particular image along with the tag, write out the provided command:

docker images "*img*:V1.0"

This command displays the image containing the word “img” and has a “V1.0” tag.

Conclusion

To filter the Docker images by the pattern with wildcards, the “docker images “<wildcard-pattern>”” command is used. The, “<wildcard-pattern>” can be a partial or full image name or tag, and a wildcard character “*” is used to match any characters before or after the pattern. This article has explained the method to filter Docker images by pattern using wildcards.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.