Can’t Push Docker Image to Amazon ECR? Fix “no basic auth credentials” Error

Amazon Elastic Container Registry (ECR) is a powerful and secure container registry service by AWS. However, one of the most common issues users encounter when pushing Docker images to ECR is the frustrating error:

no basic auth credentials

If you’re stuck with this error, don’t worry. This post explains why this happens and how to fix it step-by-step.


🧠 Why This Error Happens

The no basic auth credentials error occurs when Docker tries to push an image to Amazon ECR, but:

  • You’re not authenticated with ECR, or
  • Docker can’t find the login token in its config, or
  • You’re using a profile or region mismatch

In short: Docker doesn’t know how to access ECR securely.


✅ Step-by-Step Fix

Follow these steps to properly authenticate and push your Docker image to Amazon ECR.


1. ✅ Authenticate Docker to ECR

Run the following command to authenticate Docker with ECR:

aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<your-region>.amazonaws.com

Replace:

  • <your-region> with your AWS region (e.g., us-east-1)
  • <account-id> with your 12-digit AWS account ID

Example:

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

This command:

  • Retrieves a temporary token using your AWS credentials
  • Passes it to Docker to authenticate securely

💡 Make sure your AWS CLI is configured with a valid profile and permissions.


2. 🏷️ Tag Your Docker Image for ECR

Tag your local Docker image using the full ECR repository URI:

docker tag my-app:latest 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest

3. 📤 Push the Docker Image

Now push the tagged image:

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

If authentication was successful, Docker will start uploading the image layers.


🛑 Still Getting the Error? Try These Fixes

🔐 Check AWS Credentials

Make sure you’ve configured AWS credentials on your machine:

aws configure

Or explicitly specify a profile:

aws --profile myprofile ecr get-login-password ...

🌎 Confirm Your AWS Region

The login region (--region) must match the region of the ECR repository.


🧾 Ensure IAM Permissions

Your IAM user or role must have the following permissions:

"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"

🔄 Update Docker & AWS CLI

Outdated versions can cause compatibility issues:

docker --version
aws --version

Update if needed:


📝 Summary

StepDescription
1.Authenticate Docker with ECR using get-login-password
2.Tag image with full ECR repo URI
3.Push image using docker push
4.Verify region, credentials, and permissions if issues persist

✅ Conclusion

The "no basic auth credentials" error simply means Docker isn’t authenticated to push to ECR. Using the aws ecr get-login-password command resolves this by setting up the proper credentials.

Make sure your AWS CLI, Docker, IAM permissions, and regions are correctly configured—and you’ll be pushing images to ECR in no time.

Sharing Is Caring:

Leave a Comment