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/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/my-base-image:latest
Error response from daemon: Head ";: no basic auth credential
I should be able to pull the image successfully
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
Share Improve this question asked Feb 5 at 14:20 JudiJudi 9124 gold badges15 silver badges32 bronze badges2 Answers
Reset to default 0You 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
.
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
).