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


当前回答

即使没有打开权限,这也应该可以工作。请参阅文档:私有注册中心身份验证。

[编辑:实际上,我在做第二次测试时也遇到了权限问题。参见Docker推送到AWS ECR私有回购失败,JSON格式不正确)。

然而,我也遇到了同样的问题;我不知道为什么,但我成功地使用了文档中描述的get-authorization-token的更冗长的认证机制

AWS CLI和Docker版本:

$ aws --version
aws-cli/1.9.17 Python/2.7.6 Linux/3.16.0-38-generic botocore/1.3.17
$ docker --version
Docker version 1.9.1, build a34a1d5

获取认证令牌('docker密码')。

aws ecr get-authorization-token --region us-east-1 --output text \
    --query authorizationData[].authorizationToken | base64 -d | cut -d: -f2

注:My ~/。aws/config指定了一个不同的默认区域,所以我需要显式地设置——region us-east-1。

交互式登录(将############更改为您的AWS帐户id):

docker login -u AWS https://############.dkr.ecr.us-east-1.amazonaws.com/
password: <paste the very long password from above>
email: <I left this blank>

推送一个图像(假设你已经做了一个docker图像测试):

docker tag test:latest ############.dkr.ecr.us-east-1.amazonaws.com/test:latest
docker push ############.dkr.ecr.us-east-1.amazonaws.com/test:latest
The push refers to a repository [910732017890.dkr.ecr.us-east-1.amazonaws.com/test] (len: 1)
d5122f58a2e1: Pushed 
7bddbca3b908: Pushed 
latest: digest: sha256:bc0b521fd398bd1a2ef58a289dcb910334608723fd570e7bddb36eacd0060363 size: 4378

其他回答

我们今天也遇到了这个问题,并尝试了本文中提到的所有方法(除了生成AWS凭据)。

我们最终通过简单地升级Docker解决了这个问题,然后推送工作了。

Docker 1.10遇到了这个问题。Docker 1.11.x解决了这个问题。

希望这能有所帮助

我在Docker论坛上发布了一个答案。在我的案例中,问题是centos“docker”不等同于docker CE,因此失败了:

没有基本认证

我只是通过在centos上安装“docker-ce”来修复。

参考:https://forums.docker.com/t/docker-push-to-ecr-failing-with-no-basic-auth-credentials/17358/30

在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 --region us-west-1 --no-include-email

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

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

如果你运行$(aws ecr get-login——region us-east-1),一切都会为你完成

2021年7月更新:

在AWS CLI的版本1中,get-login现在已弃用。如果您正在使用AWS CLI的版本2,则必须使用get-login-password。

您可以将get-login-password的输出输出到docker登录命令,以验证docker到您的ECR注册表:

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

现在你应该能够docker推送,并让它直接进入你的ECR注册表。