How to Fix ‘no basic auth credentials’ with Docker and AWS ECR

If you are trying to push a Docker image to AWS ECR (Elastic Container Registry) and you get a no basic auth credentials error. Then you can easily fix it as follows!

Replicating the no basic auth credentials error

You ran something like this:

docker tag <image> <account>.dkr.ecr.<region>.amazonaws.com/<app> docker push <image> <account>.dkr.ecr.<region>.amazonaws.com/<app>
Code language: Bash (bash)

You saw something like this:

Using default tag: latest The push refers to repository [<account>.dkr.ecr.<region>.amazonaws.com/<app>] 2e6d5f7bxxxx: Preparing d8db3303xxxx: Preparing 32f366d6xxxx: Preparing no basic auth credentials
Code language: Bash (bash)

How to fix the problem no basic auth credentials error

Run the following AWS CLI to see if you are able to login with the system available config.

$(aws ecr get-login --region <region>)
Code language: Bash (bash)

Remember to swap <region> out with your region you are using in the docker tag and docker push commands. For example: eu-west-1 or us-east-1.

At this point, you will probably get an error as follows:

An error occurred (UnrecognizedClientException) when calling the GetAuthorizationToken operation: The security token included in the request is invalid.
Code language: Bash (bash)

Run aws configure and enter your AWS Access Key ID and AWS Secret Access Key.

Once done, run the above command again, and you should not get the GetAuthorizationToken error anymore.

Instead, it will have run a docker login -u AWS <token> <path> command for you.

If you get the following error: unknown shorthand flag: 'e' in -e, then run the previous command again, without the $( and ). So only run aws ecr get-login --region <region>

It will output a set of commands for you to copy in the terminal directly. Make sure to remove the -e none near the end, and execute the command.

Once this is done, Docker will provide a Login Succeeded prompt.

You can now run your docker push <image> <account>.dkr.ecr.<region>.amazonaws.com/<app> command once again.

This time everything will have worked!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments