Can't push image to Amazon ECR - fails with “n

2019-01-16 05:00发布

I'm trying to push a docker image to an Amazon ECR registry. I'm using docker client Docker version 1.9.1, build a34a1d5. I use "aws ecr get-login --region us-east-1" to get the docker login creds. I then successfully login with those creds as follows:

docker login -u AWS -p XXXX -e none https://####.dkr.ecr.us-east-1.amazonaws.com
WARNING: login credentials saved in /Users/ar/.docker/config.json
Login Succeeded

But when I try to push my image I get the following error:

$ docker push ####.dkr.ecr.us-east-1.amazonaws.com/image:latest
The push refers to a repository [####.dkr.ecr.us-east-1.amazonaws.com/image] (len: 1)
bcff5e7e3c7c: Preparing 
Post https://####.dkr.ecr.us-east-1.amazonaws.com/v2/image/blobs/uploads/: no basic auth credentials

I made sure that the aws user had the correct permissions. I also made sure that the repository allowed that user to push to it. Just to make sure that wasn't an issue I set the registry to allow all users full access. Nothing changes the "no basic auth credentials" error. I don't know how to begin to debug this since all the traffic is encrypted.

UPDATE

So I had a bit of Homer Simpson D'Oh moment when I realized the root cause of my problem. I have access to multiple AWS accounts. Even though I was using aws configure to set my credentials for the account where I had setup my repository the aws cli was actually using the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. So when I did aws ecr get-login it was returning a login for the wrong account. I failed to notice that the account numbers were different until I just went back now to try some of the proposed answers. When I remove the environment variables everything works correctly. I guess the motto of the story is if you hit this error, make sure that the repository you are logging into matches the tag you have applied to the image.

29条回答
Lonely孤独者°
2楼-- · 2019-01-16 05:49

In my case (and probably in all cases), this error resulted from having multiple AWS accounts. So, AWS ECR is not using the right aws credentials assosciated with the aws account.

I tried multiple solutions mentioned here, but did not succeed. It worked after using tokens instead of username and password. I got it working following the instructions here. https://btburnett.com/2017/01/docker-login-for-amazon-aws-ecr-using-windows-powershell.html

查看更多
Bombasti
3楼-- · 2019-01-16 05:50

I had this issue as well. What happened with me was I forgot to run the command that was returned to me after I ran

aws ecr get-login --region ap-southeast-2

This command returned a big blob, which includes the docker login command right there! I didn't realise. It should return something like this:

docker login -u AWS -p <your_token_which_is_massive> -e none <your_aws_url>

Copy and paste this command & then run your docker push command which looks something like this:

docker push 8888888.blah.blah.ap-southwest-1.amazonaws.com/dockerfilename
查看更多
Ridiculous、
4楼-- · 2019-01-16 05:50

we also encounter this issue today and tried everything mentionned in this post (except generating AWS credentials).

We finally solved the problem by simply upgrading Docker, then the push worked.

The problem was encountered with Docker 1.10.x and was solved with Docker 1.11.x.

Hope this helps

查看更多
手持菜刀,她持情操
5楼-- · 2019-01-16 05:50
aws ecr get-login --region us-west-1 --no-include-email

This command gives me correct command to login. If you dont use "--no-include-email",it will throw another error. Output of the above command looks like this docker login -u AWS -p **********************very big******. Copy that and execute it. Now it will show "Login Succeeded". Now you can push your image to ECR.

Make sure that your AMI rule has the permission for the user you tried to login.

查看更多
地球回转人心会变
6楼-- · 2019-01-16 05:54

There's a known bug in the wincred credential manager on Windows. Removing 'https://' from the generated login command solves this.

docker login -u AWS -p <password> <aws_account_id>.dkr.ecr.<region>.amazonaws.com

instead of

docker login -u AWS -p <password> https://<aws_account_id>.dkr.ecr.<region>.amazonaws.com

See also the troubleshooting page.

查看更多
Rolldiameter
7楼-- · 2019-01-16 05:54

The docker command given by aws-cli is little off...

When using docker login, docker will save a server:key pair either in your keychain or ~/.docker/config.json file

If it saves the key under "https://7272727.dkr.ecr.us-east-1.amazonaws.com" the lookup for the key during push will fail because docker will be looking for a server named “7272727.dkr.ecr.us-east-1.amazonaws.com” not "https://7272727.dkr.ecr.us-east-1.amazonaws.com".

Use the following command to login:
eval $(aws ecr get-login --no-include-email --region us-east-1 --profile yourprofile | sed 's|https://||')

Once you run the command you will get 'Login Succeeded' message and then you are good
after that your push command should work

查看更多
登录 后发表回答