简体   繁体   中英

Docker ImagePush failing with “no basic auth credentials”

I'm attempting to use the docker go-sdk to push an image to AWS ECR.

This is the code I'm using to push the image.

where tag = ".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
}

But I keep getting this response:

{"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"}

Any ideas?

Notes:

  • I've verified that the credentials string I'm passing in is a base64 encoded user:pass for the ECR registry.
  • I've verified that the ECR credentials I'm getting are from the same AWS Region as where im attempting to push the image.

I found out in a GitHub comment that RegistryAuth actually needs to be a base64 JSON string with username and password fields. Ugh. This is undocumented in the Docker repository.

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

Relevant GitHub comment .

It is working for me now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM