无法将 Docker 镜像使用 Docker Go SDK 推送到 ECR

huangapple go评论89阅读模式
英文:

Failure to Push Docker Image to ECR w/ Docker Go SDK

问题

我正在使用Go的Docker客户端SDK,并且在将镜像推送到我的AWS ECR时遇到了问题。

以下是我的函数的要点:

import (
    "github.com/docker/docker/api/types"
    dockerclient "github.com/docker/docker/client"
)

func doPush(target string) {
    envCli, err := dockerclient.NewEnvClient()
    if err != nil {
        panic(err)
    }

    rc, err := envCli.ImagePush(
        context.Background(),
        target,
        types.ImagePushOptions{})
    if err != nil {
        panic(err)
    }
    defer rc.Close()
}

我的镜像标记类似于 [regid].dkr.ecr.us-east-1.amazonaws.com/demo:latest,但是我收到以下错误消息:

无效的引用格式

如果我从镜像名称中删除 [:tag],它可以工作,直到我收到以下错误消息:

来自守护程序的错误响应:错误的参数和缺少 X-Registry-Auth: EOF

英文:

I'm using the docker client SDK for Go and I'm running to an issue with pushing images to my AWS ECR.

Here is the gist of my func

import (
    "github.com/docker/docker/api/types"
    dockerclient "github.com/docker/docker/client"
)
func doPush(target string) {
    envCli, err := dockerclient.NewEnvClient()
    if err != nil {
        panic(err)
    }

    rc, err := envCli.ImagePush(
        context.Background(),
        target,
        types.ImagePushOptions{})
    if err != nil {
        panic(err)
    }
    defer rc.Close()
}

My image is tagged something like [regid].dkr.ecr.us-east-1.amazonaws.com/demo:latest but I get the following error:

> invalid reference format

If I remove the [:tag] from the image name, it works until I get a
> Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF

答案1

得分: 4

我遇到了同样的问题,并通过给docker push选项提供一个任意的RegistryAuth来解决了它。

所以以下代码可以工作:

closer, err = dockerClient.ImagePush(context.Background(), privateTagName,
                                     types.ImagePushOptions{
					All:           true,
					RegistryAuth:  "123",
				})
if err != nil {
  panic(err)
}
io.Copy(os.Stdout, closer)
closer.Close()

我在这篇帖子中读到,给RegistryAuth赋予任何值都可能起作用。

英文:

I had the same problem, and I solved it giving an arbitrary RegistryAuth to the docker push option.

So the following code works :

closer, err = dockerClient.ImagePush(context.Background(), privateTagName,
                                     types.ImagePushOptions{
					All: true,
					RegistryAuth:"123",
				})
if err != nil{
  panic(err)
}
io.Copy(os.Stdout, closer)
closer.Close()

I read in this post that giving any value to RegistryAuth could work.

huangapple
  • 本文由 发表于 2017年6月7日 06:58:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/44400971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定