Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker push to Amazon ECR stops with: no basic auth credentials

Errorno basic auth credentials

Short answer

Docker has no stored login for the registry host in your image tag. ECR tokens last 12 hours and belong to one registry URI, so the login either never ran, ran long ago, or ran for a different account or region. Run get-login-password piped into docker login for the same URI as the tag.

  • Applies to Docker Engine 28, AWS CLI 2, Amazon ECR private registry
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the registry host out of the image name you are pushing. The part before the first slash is the registry; the login must be for exactly that host.

    docker image ls --format '{{.Repository}}:{{.Tag}}' | grep dkr.ecr
  2. 2Match what you see, then jump to its fix

    1. 1The push worked yesterday, or on another machine, and fails today with no other changeNo login has been done, or the 12-hour token has expiredFix
    2. 2docker login succeeded, but the image name carries another account id or regionYou logged in to a different registry than the one in the tagFix

What does the error look like?

  • no basic auth credentials

Cause 1 of 2

No login has been done, or the 12-hour token has expired

1Check

An ECR authorization token is valid for 12 hours. After that Docker still holds an old entry, but ECR no longer accepts it, and a fresh shell or CI job has none at all.

aws sts get-caller-identity

2Fix

Get a new token and pass it to docker login on standard input. The user name is always AWS, and the last argument is the registry URI.

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com

3Verify

The command prints Login Succeeded, and the push now goes through.

docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-repository:latest

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 2

You logged in to a different registry than the one in the tag

1Check

Each ECR registry needs its own authentication. A login for one account or region does not cover another one, so compare the account id and region in the tag with the ones you used for login.

docker image ls --format '{{.Repository}}' | grep dkr.ecr
aws configure get region

2Fix

Log in once for every registry you use, with the matching region and account id. Then retag the image if the tag points at the wrong registry.

aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.eu-west-1.amazonaws.com
docker tag my-app:latest 123456789012.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest

3Verify

Push the retagged image.

docker push 123456789012.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Run the login as the first step of every build script or CI job, since a token lives only 12 hours.
  • Create the repository before the first push, or use a repository creation template.
  • On a developer laptop, consider the Amazon ECR credential helper so tokens are fetched for you.
  • Keep the registry URI in one variable so the login and the tag cannot drift apart.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.