How to Fix ‘No Basic Auth Credentials’ With Docker and AWS ECR

  • Home /
  • Blog Posts /
  • 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><app>
docker push <image> <account>.dkr.ecr.<region><app>

You saw something like this:

Using default tag: latest
The push refers to repository [<account>.dkr.ecr.<region><app>]
2e6d5f7bxxxx: Preparing
d8db3303xxxx: Preparing
32f366d6xxxx: Preparing
no basic auth credentials

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>)

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.

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 <meta charset="utf-8">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 <meta charset="utf-8">docker push <image> <account>.dkr.ecr.<region><app> command once again.

This time everything will have worked!