在golang的docker sdk中,可以使用Registry API来获取远程仓库的镜像资源信息,包括latest版本的镜像id。具体操作步骤如下:

  1. 创建Docker Registry客户端对象
import (
    "github.com/docker/docker/registry"
)

// 创建Registry客户端对象
registryClient := registry.NewClient(nil, "https://registry-1.docker.io/v2/", "", "", "")
  1. 获取远程仓库的latest版本的镜像资源信息
import (
    "github.com/docker/docker/api/types"
)

// 获取远程仓库的latest版本的镜像资源信息
manifest, err := registryClient.ManifestV2("library/alpine", "latest")
if err != nil {
    // 处理错误
}

// 获取镜像id
imageID := manifest.Config.Digest.String()

注意,上述代码中的library/alpine是镜像名称,latest是标签名称,需要根据实际情况进行替换。此外,使用Registry API需要提供认证信息,可以通过registry.NewClient函数的后两个参数来传递认证信息。如果不需要认证,可以将这两个参数设置为空字符串


原文地址: https://www.cveoy.top/t/topic/fePJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录