我正在尝试将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证书;因为我试图部署到开发,这是有效的:

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

其他回答

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

我们今天也遇到了这个问题,并尝试了本文中提到的所有方法(除了生成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

更新

由于AWS CLI版本2 - AWS ecr get-login已弃用,正确的方法是AWS ecr get-login-password。

因此,正确的最新答案如下: docker login -u AWS -p $(AWS ecr get-login-password——region us-east-1) xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com

确保在aws ecr get-login中使用正确的区域,它必须与创建存储库的区域匹配。