1

I am trying to login to docker & ecr in a single command in mac os.

So far I got till this :

aws ecr get-login --region ap-south-1 | docker login --username AWS --password-stdin Xxxx.dkr.ecr.ap-south-1.amazonaws.com 

Error response from daemon: login attempt to https://xxx.dkr.ecr.ap-south-1.amazonaws.com/v2/ failed with status: 400 Bad Request

Any idea how to solve this?

aws ecr get-login --region ap-south-1 

has the response, am trying to pipe that to next command

docker login -u AWS -p **KEY** https://xx.dkr.ecr.ap-south-1.amazonaws.com

4 Answers 4

2

First, make sure that you're upgrading your AWS CLI to the latest version. Then, use the following command (replacing AWS_ACCOUNT_ID with your actual account ID):

$ aws ecr get-login-password --region ap-south-1 | \
  docker login --username AWS --password-stdin AWS_ACCOUNT_ID.dkr.ecr.ap-south-1.amazonaws.com

See also the ECR docs.

0
1

I was using wrong account id and the following helped me. First run:

aws sts get-caller-identity

You should get an output that looks like this:

{
    "UserId": "AIDAUQ6COKW7R5SO7XYZ",
    "Account": "311256041234",
    "Arn": "arn:aws:iam::311256041234:user/john" 
}

And use the account id, not "john" or the "UserId"(replace your_region):

aws ecr get-login-password --region your_region | docker login --username AWS --password-stdin 311256041234.dkr.ecr.your_region.amazonaws.com
1

Better late than never.

AWS Labs published an helper tool to ease the authentication against ECR.

https://github.com/awslabs/amazon-ecr-credential-helper

0

My problem was that I did not correctly match the region in the aws ecr get-login-password command with the region in the registry URL. In other words, I had:

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com

And it should be:

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com

Not the answer you're looking for? Browse other questions tagged or ask your own question.