5

I want to use docker image hosted on ECR and i want to automate the pull operation using cloudformation template.

I attached IAM role with ECR full access to ec2 instance and it doesn't work.

i am doing docker pull 1234567897.dkr.ecr.us-west-2.amazonaws.com/repo:tag and iam getting the error Error response from daemon: Get https://1234567897.dkr.ecr.us-west-2.amazonaws.com/repo:tag/manifests/latest: no basic auth credentials

Nani
  • 155
  • 1
  • 2
  • 6

3 Answers3

8

Using ECR, EC2 and docker, you are still required to do a docker login.

In the user data run

aws ecr get-login --no-include-email > login.sh

bash login.sh

then you should be able to run

docker pull ecr_registry/repo:tag

https://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_AWSCLI.html

strongjz
  • 822
  • 4
  • 7
1

If you are running a EC2 Instance running Windows then you need to run the powershell equivalent command of aws ecr get-login which is

Invoke-Expression –Command (Get-ECRLoginCommand –Region region).Command
Ishan
  • 111
  • 1
0

The accepted answer is correct, i will just add a one-liner example:

run:

$(aws ecr get-login --no-include-email)

and then:

docker pull <ecr_host>/<repo>:<tag>
NotSoShabby
  • 109
  • 1
  • Not sure why this was down-voted. If you add —region for those of us not in the US ;-) it works very well. – Tim Jun 05 '20 at 14:18