Docker push to ECR failing with "no basic auth credentials"

Your problem is that the docker command given by aws-cli is slightly off.

When using docker login, docker will save a server:key pair either in your ~.docker/config or your keychain.

If it saves the key under “https://12345.dkr.ecr.eu-central-1.amazonaws.com” the lookup for the key during push will fail because docker will be looking for a server named “12345.dkr.ecr.eu-central-1.amazonaws.comnothttps://12345.dkr.ecr.eu-central-1.amazonaws.com”.

The solution therefore is to use the following wrapper to log in:
eval $(aws ecr get-login | sed 's|https://||')

This command gets the login command, replaces https:// with `` (empty string) and evaluates the resulting command. This will store the received key under the correct server and you can use it for docker push.

5 Likes