The ProblemYou run docker push and expect your image to head to the cloud. Instead, it fails instantly. You see a frustrating 'no basic auth credentials' error, even though everything worked perfectly yesterday. This usually happens because your local Docker environment has lost its connection to the AWS mothership.
$ docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
The push refers to repository [123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app]
Error response from daemon: no basic auth credentials
Why This HappensThe core issue is simple: your Docker client is no longer authenticated. Usually, it means your session token died.
AWS ECR authorization tokens are short-lived. By default, they expire every 12 hours. This is a security feature to ensure that compromised credentials don't grant indefinite access. Unlike Docker Hub, where a login might last for weeks, ECR requires you to refresh your 'password' at least twice a day if you're pushing frequently.
Step-by-Step Fix### 1. Check Your AWS IdentityFirst, verify who you are in the terminal. AWS might be trying to use a different set of credentials than you expect. Run this to see your current active profile:
aws sts get-caller-identity
If this returns an error, your AWS CLI isn't configured. Run aws configure to set your Access Key and Secret Key before proceeding.
2. Refresh the Token (AWS CLI v2)Most modern setups use AWS CLI version 2. Use the get-login-password command to fetch a fresh token and pipe it directly into Docker. It’s the cleanest way to log in.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com
Quick checklist:
- Swap
us-east-1for your actual region (likeeu-west-1). - Replace
123456789012with your 12-digit AWS Account ID. - Keep the username as
AWS. It is a static string, not your IAM name.
3. The Fix for AWS CLI v1 (Legacy)If you're maintaining an older build server with CLI v1, the command is slightly different. It generates a full command string that you must execute using a subshell:
$(aws ecr get-login --no-include-email --region us-east-1)
4. Managing Multiple ProfilesJuggling work and personal AWS accounts? You might be authenticated for the wrong one. Force the CLI to use a specific profile by adding the flag:
aws ecr get-login-password --region us-east-1 --profile work-profile | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com

