Golang Docker SDK 获取镜像仓库地址:以 CentOS 为例
可以使用client.ImageInspectWithRaw方法来获取镜像的详细信息,包括镜像的仓库地址。
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
func main() {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
panic(err)
}
imageName := "centos"
imageInspect, _, err := cli.ImageInspectWithRaw(context.Background(), imageName)
if err != nil {
panic(err)
}
repoTags := imageInspect.RepoTags
for _, tag := range repoTags {
fmt.Println(tag)
}
}
以上代码会输出centos:latest,这是镜像在Docker Hub上的地址。
原文地址: https://www.cveoy.top/t/topic/fKlm 著作权归作者所有。请勿转载和采集!