用于Redhat基本图像的API获取图像标签的值?

时间:2019-12-21 11:54:49

标签: docker redhat-containers

我们是否有API可以以编程方式获取下图的图像标签的值?

https://access.redhat.com/containers/?tab=tags&get-method=registry-tokens#/registry.access.redhat.com/rhel7

用例: 如果有新的标记版本可用,请获取更高的版本。

我正在寻找类似以下的内容:

wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O -  | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'  | awk -F: '{print $3}'

以上解决方案来自stackoverflow问题:

https://stackoverflow.com/questions/28320134/how-can-i-list-all-tags-for-a-docker-image-on-a-remote-registry

我做到了

wget https://access.redhat.com/containers/?tab=tags&get-method=registry-tokens#/registry.access.redhat.com/rhel7

不幸的是,它提供了很多多余的数据,无济于事。

我很感激任何线索。

谢谢

1 个答案:

答案 0 :(得分:1)

一种选择是使用skopeo命令来获取有关远程映像的信息。例如,如果您运行:

skopeo inspect docker://registry.access.redhat.com/rhel7

您将获得大量JSON数据,其中包括有关所有可用标签的信息:

{
    "Name": "registry.access.redhat.com/rhel7",
    "Digest": "sha256:11ec91dcb3505f6eaa02d815fab39078786f3ddbef26796e3ef348410ca43b9d",
    "RepoTags": [
        "7.3-74",
        "7.4-120",
        "7.2-56",
        "7.3-89",
        "7.3-66",
        "7.5-424",
        "7.5-245.1527091554",
        "7.4-129",
        "7.1-12",
        "7.6-122",
        "7.3-82",
        "7.7-384.1575996163",
        "7.5-409.1533127727",
        "7.2-75",
        "7.2-38",
        "7.6",
[...]

(总共约有70个。)

由于skopeo返回JSON结果,因此很容易获取此输出并以编程方式对其进行解析以提取所需的信息。


使用skopeoskopeo --debug ...)的调试输出,我发现https://registry.access.redhat.com/v2/rhel7/tags/list也提供了标记列表。在没有身份验证的情况下似乎可以正常工作,所以也许这是最简单的选择。