0

我正在尝试使用 docker go-sdk 将图像推送到 AWS ECR。

这是我用来推送图像的代码。

其中标签 =“.dkr.ecr.us-east-1.amazonaws.com/api:mytag”

func Push(c context.Context, tag string, credentials string) error {
    cli, err := client.NewClient(apiSocket, apiVersion, nil, apiHeaders)
    if err != nil {
        return err
    }
    fmt.Println(credentials)

    resp, err := cli.ImagePush(c, tag, types.ImagePushOptions{
        RegistryAuth: credentials,
    })
    if err != nil {
        panic(err)
    }

    io.Copy(os.Stdout, resp)
    resp.Close()

    return nil
}

但我不断收到这样的回复:

{"status":"The push refers to repository [<id>.dkr.ecr.us-east-1.amazonaws.com/api]"}
{"status":"Preparing","progressDetail":{},"id":"23432919a50a"}
{"status":"Preparing","progressDetail":{},"id":"9387ad10e44c"}
{"status":"Preparing","progressDetail":{},"id":"e2a4679276bf"}
{"status":"Preparing","progressDetail":{},"id":"31c5c8035e63"}
{"status":"Preparing","progressDetail":{},"id":"a73789d39a06"}
{"status":"Preparing","progressDetail":{},"id":"f36942254806"}
{"status":"Preparing","progressDetail":{},"id":"4a2596f9aa79"}
{"status":"Preparing","progressDetail":{},"id":"5cf3066ccdbc"}
{"status":"Preparing","progressDetail":{},"id":"76a1661c28fc"}
{"status":"Preparing","progressDetail":{},"id":"beefb6beb20f"}
{"status":"Preparing","progressDetail":{},"id":"df64d3292fd6"}
{"status":"Waiting","progressDetail":{},"id":"beefb6beb20f"}
{"status":"Waiting","progressDetail":{},"id":"df64d3292fd6"}
{"errorDetail":{"message":"no basic auth credentials"},"error":"no basic auth credentials"}

有任何想法吗?

笔记:

  • 我已验证我传入的凭据字符串是 base64 编码的 user:pass 用于 ECR 注册表。
  • 我已验证我获得的 ECR 凭证与我尝试推送图像的 AWS 区域相同。
4

1 回答 1

2

我在 GitHub 评论中发现RegistryAuth实际上需要是带有用户名和密码字段的 base64 JSON 字符串。啊。这在 Docker 存储库中没有记录。

RegistryAuth = "{ \"username\": \"myusername\", \"password\": \"mypassword\", \"email\": \"myemail\" }

相关 GitHub 评论

它现在对我有用。

于 2018-12-04T21:24:06.530 回答