Docker : Error saving credentials: error storing credentials – err: exec: “docker-credential-ecr-login” – Solved

The error message you’re seeing is due to the AWS ECR credential helper docker-credential-ecr-login not being found in your system’s PATH. This helper simplifies the process of authentication with ECR, eliminating the need for aws ecr get-login and docker login.

Here are the steps you can follow to install and configure the Amazon ECR Docker Credential Helper:

The amazon-ecr-credential-helper package is not available directly through the apt-get package manager for Ubuntu. Instead, it must be downloaded and installed manually from the source.

Here’s how to do it:

First, install the prerequisite packages:

sudo apt-get install -y golang-go git

Then, set the GOPATH:

echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc

Now, you can download and compile the Amazon ECR Docker Credential Helper:

go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login

Finally, update the Docker configuration (~/.docker/config.json) to use the Amazon ECR Docker Credential Helper for Docker commands:

mkdir -p ~/.docker
echo '{ "credsStore": "ecr-login" }' > ~/.docker/config.json

Now, when you use Docker commands that require authentication with an ECR registry, Docker will automatically use the Amazon ECR Docker Credential Helper to authenticate.

Please ensure to replace placeholder values in the commands above with your actual values. As with all commands that use sudo, ensure you understand what they do and use them carefully, as they have administrative permissions.

To login again and refresh the token, you can use the following command:

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

Please remember to use sudo if your Docker installation requires elevated permissions.

After running this command, your Docker should be authenticated with ECR and you should be able to pull your image.

If you have installed and configured the Amazon ECR Credential Helper as described in the previous steps, Docker should be using it to authenticate with your ECR registry automatically, and you should not have to run the aws ecr get-login-password command regularly.

Follow these steps to troubleshoot the issue:

Check if the executable is installed and confirm its location. Use the which command to find the path of the executable:

which docker-credential-ecr-login

If the command returns a path, the executable is installed and the issue lies elsewhere. If the command doesn’t return anything, the executable either isn’t installed or isn’t in the system’s PATH.

Check if the path of the executable is included in the system’s PATH. You can view the directories included in the PATH using:

echo $PATH

If the path to the executable is not included, you can add it to the PATH. Let’s assume the path to the docker-credential-ecr-login executable is /home/ubuntu/go/bin. You can add this path to the system’s PATH using:

echo 'export PATH=$PATH:/home/ubuntu/go/bin' >> ~/.bashrc
source ~/.bashrc

Check Docker’s configuration file. The configuration file is usually located at ~/.docker/config.json. Open it and confirm that it has the correct configuration:

{
    "credsStore": "ecr-login"
}
Author: user

Leave a Reply