我正在尝试将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.


当前回答

我在OSX上运行时也遇到了这个问题。我看到了Oliver Salzburg的响应,并检查了我的~/.docker/config.json。它里面有来自我拥有的不同AWS帐户的多个授权凭证。我删除了该文件,再次运行get-login后,它工作了。

其他回答

在Windows上的wincred凭证管理器中有一个已知的错误。从生成的登录命令中删除'https://'可以解决这个问题。

docker login -u AWS -p <password> <aws_account_id>.dkr.ecr.<region>.amazonaws.com

而不是

docker login -u AWS -p <password> https://<aws_account_id>.dkr.ecr.<region>.amazonaws.com

请参见故障排除页面。

我不得不运行aws ecr get-login-password,因为aws cli已弃用get-login命令。

此外,在这个版本中,用户名被强制硬编码为AWS。

下面是适用于aws-cli/2.0.58的命令。

aws ecr get-login-password --region region_y | docker login --username AWS --password-stdin account_x.dkr.ecr.region_y.amazonaws.com

登录成功

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

在PowerShell的Windows上,使用:

Invoke-Expression $(aws ecr get-login --no-include-email)

在Windows系统上,你必须清空下面的文件~/.docker/config。Json,然后再次运行下面的脚本

aws ecr get-login --no-include-email --region ap-southeast-1 --profile [profile_name]