我正在尝试将docker映像推送到Amazon ECR注册表。我使用docker客户端docker版本1.9.1,构建a34a1d5。我使用aws ecr get-login -region us-east-1来获得docker登录信用。然后我成功登录这些学分如下:

docker login -u AWS -p XXXX -e none https://####.dkr.ecr.us-east-1.amazonaws.com
WARNING: login credentials saved in /Users/ar/.docker/config.json
Login Succeeded

但当我试图推动我的图像,我得到以下错误:

$ docker push ####.dkr.ecr.us-east-1.amazonaws.com/image:latest
The push refers to a repository [####.dkr.ecr.us-east-1.amazonaws.com/image] (len: 1)
bcff5e7e3c7c: Preparing 
Post https://####.dkr.ecr.us-east-1.amazonaws.com/v2/image/blobs/uploads/: no basic auth credentials

我确保aws用户具有正确的权限。我还确保存储库允许用户推送到它。为了确保这不是一个问题,我将注册表设置为允许所有用户完全访问。没有什么可以改变“no basic auth credentials”错误。我不知道如何开始调试,因为所有的流量都是加密的。

更新

So I had a bit of Homer Simpson D'Oh moment when I realized the root cause of my problem. I have access to multiple AWS accounts. Even though I was using aws configure to set my credentials for the account where I had setup my repository the aws cli was actually using the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. So when I did aws ecr get-login it was returning a login for the wrong account. I failed to notice that the account numbers were different until I just went back now to try some of the proposed answers. When I remove the environment variables everything works correctly. I guess the motto of the story is if you hit this error, make sure that the repository you are logging into matches the tag you have applied to the image.


当前回答

aws-cli给出的docker命令有点错误…

当使用docker登录时,docker会在你的keychain或~/.docker/config中保存一个server:密钥对。json文件

如果它将密钥保存在https://7272727.dkr.ecr.us-east-1.amazonaws.com下,在推送期间查找密钥将失败,因为docker将寻找名为7272727.dkr.ecr.us-east-1.amazonaws.com的服务器,而不是https://7272727.dkr.ecr.us-east-1.amazonaws.com。

使用以下命令登录:

eval $(aws ecr get-login --no-include-email --region us-east-1 --profile yourprofile | sed 's|https://||')

一旦你运行命令,你会得到“登录成功”的消息,然后你就好了 之后,您的push命令应该可以工作

其他回答

我的问题是拥有多个AWS证书;因为我试图部署到开发,这是有效的:

$(aws ecr get-login --no-include-email --region eu-west-1 --profile dev | sed 's|https://||')

AWS放弃了get-login,请使用以下命令

aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <ecr-repo-full-path>

例子

aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 607348619222.dkr.ecr.ap-south-1.amazonaws.com

如果您使用概要文件,不要忘记将——profile=XXX传递给aws ecr get-login。

aws ecr get-login --region us-west-1 --no-include-email

这个命令给了我正确的登录命令。如果你不使用“——no-include-email”,它将抛出另一个错误。上面命令的输出看起来像这个docker login -u AWS -p **********************very big******。复制并执行它。现在会显示“Login Succeeded”。现在您可以将映像推到ECR。

确保您的AMI规则具有您尝试登录的用户的权限。

所以我通过下载repo并自己编译来安装aws-credentials-helper。我发现我使用了错误的编译命令:make docker而不是make docker TARGET_GOOS=darwin(我在Mac上)。生成的bin/local/docker-credential-ecr-login最初是不可执行的。