List docker images with a given tag.

huangapple go评论59阅读模式
英文:

List docker images with a given tag

问题

I want to list all images with the tag foo, regardless of repository name.

What I've tried:

docker images --filter=reference='*:foo'

With the following images on the daemon:

x/y/z:foo
y/z:foo
z:foo

The above command will list only the z:foo image.

I cannot find anywhere documented how the Docker CLI interprets these wildcards. I've found other answers, where people state that you generally need to look into the Go code for that (?!). For example, in order to realize that the * wildcard will not match the / character. As long as it is not documented, I guess it is urban legend, although I can reproduce it.

In any case, I'll restate the question:

How to list all images on docker daemon with tag name foo, regardless of repository name.

英文:

I want to list all images with the tag foo, regardless of repository name.

What I've tried:

docker images  --filter=reference='*:foo'

With the following images on the daemon:

x/y/z:foo
y/z:foo
z:foo

.. the above command will list only the z:foo image.

I cannot find anywhere documented how the Docker CLI interprets these wildcards. I've found other answers, where people state that you generally need to look into the Go code for that (?!). For example, in order to realize that the * wildcard will not match the / character. As long as it is not documented, I guess it is urban legend, although I can reproduce it.

In any case, I'll restate the question:

How to list all images on docker daemon with tag name foo, regardless of repository name.

答案1

得分: 1

docker images | awk '$2 == "foo"'
x/y/z     foo            f1329e1a30c0   5周前    691MB
y/z       foo            180697b5c4fb   6周前    1.39GB
z         foo            2ee88e314807   6周前    1.51GB
英文:

You can always pipe output to other tools, like awk:

docker images | awk '$2 == "foo"'

x/y/z     foo            f1329e1a30c0   5 weeks ago    691MB
y/z       foo            180697b5c4fb   6 weeks ago    1.39GB
z         foo            2ee88e314807   6 weeks ago    1.51GB

答案2

得分: 0

@Justinas已经给出了一个很好的答案,但是关于`docker images --filter=reference`通配符的详细说明是,它不匹配`/`,但如果你真的想使用它,你可以使用多个过滤器:

```terminal
docker images --filter=reference="*:foo" --filter=reference="*/*:foo" --filter=reference="*/*/*:foo"

<details>
<summary>英文:</summary>

@Justinas has already given a good answer, but to elaborate on the `docker images --filter=reference` wildcard, it does not match `/`, but if you really want to use it you can use multiple filters:

```terminal
docker images --filter=reference=&quot;*:foo&quot; --filter=reference=&quot;*/*:foo&quot; --filter=reference=&quot;*/*/*:foo&quot;

huangapple
  • 本文由 发表于 2023年4月17日 14:29:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032239.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定