1
votes

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
2

2 Answers

2
votes

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
votes

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