如何从Sha中提取Docker映像名称

时间:2019-03-22 12:37:28

标签: docker

我正在尝试使用sha256值解析docker映像名称。码头工人是否已经提供了执行此操作的API?还是我需要自己写点东西?

根据@Zgurskyi的建议,我尝试使用inspect,以某种方式它给了我错误:

# docker images --digests
REPOSITORY                               TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
alpine                                   3.4                 sha256:b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c   b7c5ffe56db7        7 weeks ago         4.82MB

# docker image inspect b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c
[]
Error: No such image: b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c

TIA。

2 个答案:

答案 0 :(得分:1)

您可以使用inspect命令,而RepoTags可能是您需要的信息:

docker image inspect <sha256>

如果已安装jq,则只需使用以下内容:

docker image inspect <sha256> | jq .[0].RepoTags

答案 1 :(得分:1)

要解析摘要,您还需要存储库名称。例如:

docker inspect alpine@sha256:b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c

您也可以使用docker格式化,而不是依赖于jq,尽管可能确实会安装# to list the first RepoTag, this can fail if the RepoTags list is empty (locally built image): $ docker image inspect "${repo}@${sha256}" --format '{{index .RepoTags 0}}' # to list all RepoTags with a space separator: $ docker image inspect "${repo}@${sha256}" --format '{{range $v := .RepoTags}}{{$v}} {{end}}'

{{1}}
相关问题