Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Thursday, October 20, 2016

Can't push image to Amazon ECR - fails with

Can't push image to Amazon ECR - fails with "no basic auth credentials"


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.

Answer by fazy for Can't push image to Amazon ECR - fails with "no basic auth credentials"


This should have worked even without opening up the permissions. See the documentation: Private Registry Authentication.

[Edit: actually, I had permissions problems too when doing a second test. See Docker push to AWS ECR private repo failing with malformed JSON).]

Nevertheless I had the same problem; I don't know why, but I successfully used the more long-winded auth mechanism described in the docs for get-authorization-token

AWS CLI and Docker versions:

$ aws --version  aws-cli/1.9.17 Python/2.7.6 Linux/3.16.0-38-generic botocore/1.3.17  $ docker --version  Docker version 1.9.1, build a34a1d5  

Get the auth token ('docker password').

aws ecr get-authorization-token --region us-east-1 --output text \      --query authorizationData[].authorizationToken | base64 -d | cut -d: -f2  

Note: My ~/.aws/config specifies a different default region, so I needed to explicitly set --region us-east-1.

Log in interactively (change ############ to your AWS account id):

docker login -u AWS https://############.dkr.ecr.us-east-1.amazonaws.com/  password:   email:   

Push an image (assuming you've made a docker image test):

docker tag test:latest ############.dkr.ecr.us-east-1.amazonaws.com/test:latest  docker push ############.dkr.ecr.us-east-1.amazonaws.com/test:latest  The push refers to a repository [910732017890.dkr.ecr.us-east-1.amazonaws.com/test] (len: 1)  d5122f58a2e1: Pushed   7bddbca3b908: Pushed   latest: digest: sha256:bc0b521fd398bd1a2ef58a289dcb910334608723fd570e7bddb36eacd0060363 size: 4378  

Answer by temasso for Can't push image to Amazon ECR - fails with "no basic auth credentials"


I experienced the same issue.

Generating new AWS credentials (access keys) and reconfiguring AWS CLI with new credentials resolved problem.

Earlier, "aws ecr get-login --region us-east-1" generated docker login command with invalid EC registry url.

Answer by Antonio Terreno for Can't push image to Amazon ECR - fails with "no basic auth credentials"


if you run $(aws ecr get-login --region us-east-1) it will be all done for you

Answer by Greg for Can't push image to Amazon ECR - fails with "no basic auth credentials"


If you use profiles, don't forget to pass --profile=XXX to aws ecr get-login

Answer by Baptiste Gaillard for Can't push image to Amazon ECR - fails with "no basic auth credentials"


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

Answer by Oliver Salzburg for Can't push image to Amazon ECR - fails with "no basic auth credentials"


In my case this was a bug with Docker for Windows and their support for the Windows Credential Manager.

Open your ~/.docker/config.json and remove the "credsStore": "wincred" entry.

This will cause credentials to be written to the config.json directly. You'll have to log in again afterwards.

You can track this bug through the tickets #22910 and #24968 on GitHub.

Answer by Minh Tran for Can't push image to Amazon ECR - fails with "no basic auth credentials"


I ran into this issue as well running on OSX. I saw Oliver Salzburg's response and checked my ~/.docker/config.json. It had multiple authorization credentials inside it from the different AWS accounts I have. I deleted the file and after running get-login again it worked.

Answer by Dan Groch for Can't push image to Amazon ECR - fails with "no basic auth credentials"


The AWS documents tell you to execute the following command (for ap-southeast-2 region)

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

When I bumped into this issue, it wasn't clear to me based on that docs that you need to enter the result of this command into the terminal and execute it.

Fix that worked for me to was to copy the result to the clipboard with

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

Paste the result into the command line and execute it

Answer by Jason Clark for Can't push image to Amazon ECR - fails with "no basic auth credentials"


I had this issue with a different cause: I needed to push to a registry not associated with my AWS Account (a client's ECR registry). The client had granted me access under the Permissions tab for the registry, by adding my IAM id (e.g., arn:aws:iam::{AWS ACCT #}:user/{Username}) as a Principal. I tried to login with the usual steps:

$(aws ecr get-login --region us-west-2 --profile profilename)  docker push {Client AWS ACCT #}.dkr.ecr.us-west-1.amazonaws.com/imagename:latest  

Which of course resulted in no basic auth credentials. As it turns out, aws ecr get-login logs you in to the ECR for the registry associated your login, which makes sense in retrospect. The solution is to tell aws ecr get-login which registry(s) you want to log in to.

$(aws ecr get-login --region us-west-2 --profile profilename --registry-ids {Client AWS ACCT #})  

After that, docker push works just fine.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

  1 comment:

  1. Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog
    AWS Online Training

    ReplyDelete

Popular Posts

Powered by Blogger.