简体   繁体   English

[go/docker/podman]:获取容器镜像信息而不下载整个镜像

[英][go/docker/podman]: fetch container image information without downloading the whole image

I am currently developing a small program that uses constraints to check container image labels .我目前正在开发一个使用约束来检查容器图像标签的小程序。 The whole thing should run automatically in the CI.整个事情应该在 CI 中自动运行。

I am currently using docker to get the labels of the images.我目前正在使用 docker 来获取图像的标签。 However, I always have to download the container image.但是,我总是必须下载容器映像。 Now I wonder if there is a way to get the meta information without downloading the image with docker or alternatively podman.现在我想知道是否有一种方法可以在不使用 docker 或 podman 下载图像的情况下获取元信息。

If yes, I would be glad to get some sample code.如果是,我会很高兴获得一些示例代码。

There are several tools do this, including crane, skopeo, and my own regclient.有几个工具可以做到这一点,包括起重机、skopeo 和我自己的 regclient。 The specs for this are defined in OCI.此规范在 OCI 中定义。 Specifically:具体来说:

I'd recommend using a library for this, mainly to handle the authentication, which can be challenging.我建议为此使用一个库,主要用于处理身份验证,这可能具有挑战性。 Or if you just want a quick CLI, here's the example with regctl from regclient :或者,如果您只想要一个快速的 CLI,以下是 regclient 的regctl 示例

regctl image config $image_name

The above also accepts Go templates in the --format flag, allowing you to retrieve specific labels.以上还接受--format标志中的 Go 模板,允许您检索特定标签。 You can see the implementation for that, in Go, in that command definition .您可以在该命令定义中的 Go 中看到实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM