docker push to Amazon ECR stops with: no basic auth credentials
no basic auth credentialsShort 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.
Fix it fast
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.ecr2Match what you see, then jump to its fix
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-identity2Fix
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.com3Verify
The command prints Login Succeeded, and the push now goes through.
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-repository:latestConfirmed by docs.aws.amazon.com
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 region2Fix
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:latest3Verify
Push the retagged image.
docker push 123456789012.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latestConfirmed by docs.aws.amazon.com
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:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY device
Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer.
3 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
The Java SDK finds no AWS credentials on an EC2 instance or in a container on it
InstanceProfileCredentialsProvider()
The SDK walks a fixed list of credential sources and the EC2 instance role is the last one.
3 causes, each with a fixServers
cdk deploy fails in a GitLab job with spawnSync docker ENOENT
code: 'ENOENT'
ENOENT means the operating system found no docker program to run.
3 causes, each with a fixServers
A Lambda container image crashes locally with KeyError: AWS_LAMBDA_RUNTIME_API
KeyError: 'AWS_LAMBDA_RUNTIME_API'
The Lambda runtime interface client reads AWS_LAMBDA_RUNTIME_API at start-up.
2 causes, each with a fixServers
LocalStack S3 and other services refuse connections on 127.0.0.1:4566
Connection refused 127.0.0.1:4566
Connection refused on 4566 means nothing answered at the address you used.
4 causes, each with a fix