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.
If you use multiple profiles and you need to login to a profile that is not your default one, you need to login with this command:
Make sure you use the correct region in
aws ecr get-login
, it must match the region in which your repository is created.After run this command:
(aws ecr get-login --no-include-email --region us-west-2)
just run the docker login command from the output
docker login -u AWS -p epJ....
is the way that docker login into ECR
I faced the same issue and the mistake I did was using the wrong repo path
eg:
docker push xxxxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/jenkins:latest
In the above path this is where I've done the mistake: In
"dkr.ecr.us-east-1.amazonaws.com"
instead of"west"
. I was using "east"
. Once I corrected my mistake, I was able to push the image successfully.If it helps anyone...
My problem was that I had to use the
--profile
option in order to authenticate with the proper profile from the credentials file.Next, I had ommitted the
--region [region_name]
command, which also gave the "no basic auth credentials" error.The solution for me was changing my command from this:
aws ecr get-login
To this:
aws --profile [profile_name] ecr get-login --region [region_name]
Example:
aws --profile foo ecr get-login --region us-east-1
Hope that helps someone!
If you use profiles, don't forget to pass
--profile=XXX
toaws ecr get-login
.