Search code examples
amazon-web-servicesdockeramazon-ecr

Getting no basic auth credential from AWS ECR when pulling image


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


Solution

  • It looks like you're correctly logging into AWS ECR, but the issue probably stems from root vs. non-root user authentication in Docker. When you run sudo docker pull, it does not use the authentication stored in your user's ~/.docker/config.json because sudo runs as root, which has a separate home directory (/root/.docker/config.json).