I am trying to pull image from AWS ECR. I am on an EC2 machine and as you can see that I can login successfully. However, when I am trying to pull the image using docker pull I am getting Head <> : no basic auth credential
export REGION='us-east-1'
my_account_id=$(aws sts get-caller-identity --query "Account" --output text)
aws ecr get-login-password --region $REGION| docker login --username AWS --password-stdin ${my_account_id}.dkr.ecr.${REGION}.amazonaws.com/my-base-image:latest
Login Succeeded
cat ~/.docker/config.json is showing the auth
However, I am unable to pull the image --
sudo docker pull 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-base-image:latest
Error response from daemon: Head "https://123456789012.dkr.ecr.us-east-1.amazonaws.com/v2/my-base-image/manifests/latest": no basic auth credential
I should be able to pull the image successfully
You ran docker login
with your regular EC2 user account. Then you are trying to run the docker pull
with sudo
, which runs as the root
EC2 account. The root
EC2 account isn't logged into ECR. You either need to run all docker
commands with sudo
or run none of them with sudo
.