小编den*_*enn的帖子

使用 Go 访问远程 docker 存储库

我需要使用 Go 和协议 V2 访问私有 docker 注册表。我需要在私有注册表中列出存储库,获取它们的所有标签和其他信息。我应该使用 docker/distribution/registry/client 吗?有此类任务的示例吗?我找不到...官方网站只提供http api文档。

我写了一些代码:

    registry, err := client.NewRegistry("https://registry-1.docker.io/", http.DefaultTransport)
    if err != nil {
        log.Error("Error creating the registry: {}", err)
        return
    }

    ctx := context.Background()

    entries := make([]string, 5)

    numFilled, err := registry.Repositories(ctx, entries, "")
    if err != io.EOF {
        log.Error("Error getting the registry: {}", err)
        return
    }

    log.Info("Number of repositories: {}", numFilled)

    _ = registry
Run Code Online (Sandbox Code Playgroud)

当然,docker repo 需要身份验证。但我该如何提供呢?有这样的任务的文档吗?

go docker

5
推荐指数
1
解决办法
1755
查看次数

标签 统计

docker ×1

go ×1