Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to Push Docker Image to ECR w/ Docker Client SDK #33552

Open
jdgiotta opened this issue Jun 7, 2017 · 3 comments
Open

Failure to Push Docker Image to ECR w/ Docker Client SDK #33552

jdgiotta opened this issue Jun 7, 2017 · 3 comments

Comments

@jdgiotta
Copy link

jdgiotta commented Jun 7, 2017

Description

I'm using the docker client SDK and getting an invalid reference format error when attempting to push an image to an AWS ECR.

Steps to reproduce the issue:

  1. Create an image
  2. Tag image for AWS ECR [regid].dkr.ecr.us-east-1.amazonaws.com/demo:latest
  3. Run code:
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()
}

Describe the results you received:

invalid reference format

Describe the results you expected:

io.ReadCloser, nil error

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:      17.06.0-ce-rc1
 API version:  1.30
 Go version:   go1.8.1
 Git commit:   7f8486a
 Built:        Wed May 31 02:56:01 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce-rc1
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.1
 Git commit:   7f8486a
 Built:        Wed May 31 03:00:14 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 47
 Running: 1
 Paused: 0
 Stopped: 46
Images: 418
Server Version: 17.06.0-ce-rc1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 591
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3addd840653146c90a254301d6c3a663c7fd6429
runc version: 992a5be178a62e026f4069f443c6164912adbf09
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.30-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.855GiB
Name: moby
ID: MOGC:423V:4ZVP:QIXM:J22F:B35M:EUVL:3UI5:KJHY:SGD5:QEJQ:OII5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 24
 Goroutines: 34
 System Time: 2017-06-07T01:56:42.461712478Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):
Physical, macOS Sierra

@jdgiotta
Copy link
Author

jdgiotta commented Jun 7, 2017

I removed ":latest" from the image name and the error went away. Can I not specify the tag?

@ffoysal
Copy link
Contributor

ffoysal commented Jan 8, 2018

I am doing the exactly same way
my image tag is xxxx.dkr.ecr.us-east-1.amazonaws.com/my-app:1.2.3 and I m getting this
Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF not know how to add registry auth

sess, _ := session.NewSessionWithOptions(session.Options{
		SharedConfigState: session.SharedConfigEnable,
	})
	svc := ecr.New(sess)
	ain := &ecr.GetAuthorizationTokenInput{}
	aout, _ := svc.GetAuthorizationToken(ain)
	rc, er := cli.ImagePush(ctx, target, types.ImagePushOptions{
		RegistryAuth: *aout.AuthorizationData[0].AuthorizationToken,
	})

The above error has gone with the above code block.
but it did not push the image to aws nor through any errors !!!

@nadirabid
Copy link

nadirabid commented Mar 11, 2018

Wasn't able to use AuthorizationData[0].AuthorizationToken directly.

AuthorizationToken is a base64 encoded string in the format of: "<username>:<password>". It seems that ImagePushOptions.RegistryAuth needs to be a base64 encoding of "{ username: <username>, password: <password> }".

example:

	authInfoBytes, _ := base64.StdEncoding.DecodeString(*res.AuthorizationData[0].AuthorizationToken)
	authInfo := strings.Split(string(authInfoBytes), ":")
	auth := struct{
		Username string
		Password string
	} {
		Username: authInfo[0],
		Password: authInfo[1],
	}

	authBytes, _ := json.Marshal(auth)
	base64.StdEncoding.EncodeToString(authBytes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants