0

Right now I'm grabbing the ecr password via a command and piping it in to docker login to authenticate my docker client with the ECR registry

 aws ecr get-login-password --region 'us-east-1' | \
 docker login --username AWS --password-stdin <my-aws-acct-id>.dkr.ecr.us-east-1.amazonaws.com

Is there a command to tell if my docker client is already authenticated with ECR?

I tried to look at info in docker info and some other commands but it doesn't work to tell me if my docker is logged into ECR

The below doesn't work, but something like this in my shell script would be ideal:

   if docker info | grep -q "<my-aws-acct-id>.dkr.ecr.us-east-1.amazonaws.com"; then
        echo "Already logged in to ECR ✅"
    else
        echo "Not logged in to ECR"
0

1 Answer 1

1

The only way seems to be to check the docker's config.json, because the docker login command does not persist any kind of session.

You can do something like:

if cat ~/.docker/config.json | grep <your-account-id>.dkr.ecr.<your-region>.amazonaws.com; then
  echo "Already logged in to ECR ✅"
else
  echo "Not logged in to ECR"
fi;
1
  • Actually this doesn't work - there is an auths section in the config.json file but I think once you do an ecr docker login , it shows ayourname.dkr.ecr.region.amazon key in that file always - whether or not docker is logged into ECR So you still can't really tell if it's for sure logged in Commented Sep 15, 2023 at 3:58

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