Can't push image to Amazon ECR - fails with no basic auth credentials
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When working with AWS services, particularly Amazon Elastic Container Registry (ECR), a common issue encountered is failing to push container images due to "no basic auth credentials." This error can be frustrating, especially when you're trying to streamline your development workflow by integrating Docker and AWS. Here, we'll delve into why this error occurs, explore potential solutions, and provide examples to illustrate each approach.
Understanding the Error
The error message "no basic auth credentials" typically means that Docker is unable to authenticate with the Amazon ECR service. Authentication is crucial because it confirms that the person pushing the Docker image has the necessary permissions to interact with the Amazon ECR repository.
What Causes the Error
- Missing or Incorrect AWS CLI Configuration: The AWS Command Line Interface (CLI) might not be properly set up with the necessary credentials.
- Invalid or Expired Authentication Token: Docker requires an authentication token to interact with AWS ECR. Tokens have a limited lifespan and must be refreshed periodically.
- AWS IAM Policy Limitations: The IAM user or role might not have the correct permissions to perform the push operation.
Steps to Resolve the Error
Step 1: Configure the AWS CLI
Ensure that the AWS CLI is set up correctly on your local machine or build environment. Use the following command to configure it:
Provide the AWS Access Key ID, Secret Access Key, default region name, and output format when prompted.
Step 2: Retrieve an ECR Authentication Token
AWS ECR requires a token for Docker login. This token is obtained via AWS CLI:
Replace <your-region> and <your-ecr-repository-uri> with your specific details. This command fetches a temporary password and logs Docker into the ECR service.
Step 3: Verify Permissions
Check that your IAM role or user has the necessary permissions attached. The following policy grants sufficient permissions to interact with ECR:
Step 4: Troubleshooting the Docker Configuration
Ensure that your Docker configuration is correct:
- Log in to the AWS ECR repository using the correct AWS region and endpoint.
- Verify you are logged in by listing Docker's images to check if the ECR image repository appears.
This command should show your ECR repositories if you are authenticated correctly.
Example Case Study
Suppose a developer named Alex encounters this error when deploying a new microservice. The following steps outline how Alex resolved this issue:
- Alex configured the AWS CLI using
aws configure. - Obtained the ECR login token using:
- Created an IAM policy including permissions specifically for ECR operations and attached it to their IAM user or role.
- Retried the Docker push operation, which succeeded once the correct credentials and permissions were in place.
Common Pitfalls
- Expired Tokens: Tokens expire after 12 hours. Automate token retrieval in CI/CD pipelines.
- Incorrect Region or URI: Always verify you are using the correct AWS region and ECR URI.
- Configuration Errors: Double-check AWS CLI and Docker configurations to ensure all settings are correct.
Table Summarizing Key Points
| Step / Element | Description |
| AWS CLI Configuration | Use aws configure to set up AWS credentials locally. |
| ECR Authentication Token | Retrieve token with aws ecr get-login-password for authentication. |
| IAM Policy | Ensure IAM policy includes permissions like ecr:GetAuthorizationToken, ecr:PutImage. |
| Docker Configuration | Verify correct Docker login and ensure images appear with docker images. |
| Common Pitfalls | Expired tokens, incorrect regions/URIs, and configuration errors lead to authentication issues. |
By following the detailed steps and understanding the root causes of the "no basic auth credentials" error, you can efficiently resolve them and enable a streamlined workflow with AWS ECR and Docker.
Related reading
- Can't push image to Amazon ECR - fails with no basic auth credentials
- Can't run Curl command inside my Docker Container
- Celery & RabbitMQ running as docker containers Received unregistered task of type '...
- Celery in Docker container ERROR/MainProcess consumer Cannot connect to redis
- Can't see the pod logs on google GKE
- Can't SSH into AWS EC2 instance
- Capturing mobile phone traffic on Wireshark
- cert-manager letsencrypt issuing invalid certs

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.