无法将图像推送到 Amazon ECR - 因“没有基本身份验证凭证"而失败; [英] Can't push image to Amazon ECR - fails with "no basic auth credentials"

查看:21
本文介绍了无法将图像推送到 Amazon ECR - 因“没有基本身份验证凭证"而失败;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to push a docker image to an Amazon ECR registry. I'm using docker client Docker version 1.9.1, build a34a1d5. I use aws ecr get-login --region us-east-1 to get the docker login creds. Then I successfully login with those creds as follows:

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

但是当我尝试推送我的图像时,我收到以下错误:

But when I try to push my image I get the following error:

$ 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 用户具有正确的权限.我还确保存储库允许该用户推送到它.为了确保这不是问题,我将注册表设置为允许所有用户完全访问.无基本身份验证凭据" 错误没有任何改变.我不知道如何开始调试这个,因为所有的流量都是加密的.

I made sure that the aws user had the correct permissions. I also made sure that the repository allowed that user to push to it. Just to make sure that wasn't an issue I set the registry to allow all users full access. Nothing changes the "no basic auth credentials" error. I don't know how to begin to debug this since all the traffic is encrypted.

更新

所以当我意识到问题的根本原因时,我有一点 Homer Simpson D'Oh 的感觉.我可以访问多个 AWS 账户.即使我使用 aws configure 为我设置存储库的帐户设置凭据,aws cli 实际上使用环境变量 AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY.因此,当我执行 aws ecr get-login 时,它返回了错误帐户的登录信息.我没有注意到帐号不同,直到我现在回去尝试一些建议的答案.当我删除环境变量时,一切正常.我想这个故事的座右铭是,如果您遇到此错误,请确保您登录的存储库与您应用于图像的标签相匹配.

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 ecr get-login --region us-east-1) 一切都会为你搞定

if you run $(aws ecr get-login --region us-east-1) it will be all done for you

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

get-login is now deprecated in version 1 of the AWS CLI. If you're using version 2 of the AWS CLI, you must use get-login-password.

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

You can pipe the output of get-login-password to your docker login command to authenticate docker to your ECR registry:

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

现在您应该能够docker push 并将其直接发送到您的 ECR 注册表.

Now you should be able to docker push and have it go straight to your ECR registry.

这篇关于无法将图像推送到 Amazon ECR - 因“没有基本身份验证凭证"而失败;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆