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


当前回答

FWIW, Debian 9, Docker version 18.66.1 -ce, build e68fc7a:

$(aws ecr get-login | sed的| -e none | |g')

其他回答

我遇到这个问题的原因不同:我需要推送到一个与我的AWS帐户不关联的注册表(一个客户的ECR注册表)。客户已经在注册表的权限选项卡下授予了我访问权限,通过添加我的IAM id(例如,arn:aws: IAM::{aws acct#}:user/{Username})作为主体。我试着按常规步骤登录:

$(aws ecr get-login --region us-west-2 --profile profilename)
docker push {Client AWS ACCT #}.dkr.ecr.us-west-1.amazonaws.com/imagename:latest

这当然会导致没有基本的认证凭证。事实证明,aws ecr get-login将您登录到与您的登录相关联的注册中心的ecr,这在回顾中是有意义的。解决方案是告诉aws ecr get-login您想登录到哪个注册中心。

$(aws ecr get-login --region us-west-2 --profile profilename --registry-ids {Client AWS ACCT #})

在那之后,docker push工作得很好。

## If you are using 2FA in AWS : To authenticate Docker and AWS

Open Ubuntu shell or similar. (Not Windows CMD or Powershell) Run the command down below aws sts get-session-token --serial-number "User ARN" --token-code "code_from_authenticator" create temp (mfa) profile in "C:\Users\user.aws\credentials" and use the output from number 2. [mfa] aws_access_key_id = xxxx aws_secret_access_key =xxxx aws_session_token = xxx region = your region aws ecr get-login --profile mfa copy the output from 4. and run login command (delete the -e None) part Receive Successful Login! run the aws push commands

AWS文档告诉您执行以下命令(对于ap-东南-2区域)

aws ecr get-login --region ap-southeast-2

当我遇到这个问题时,根据那个文档,我不清楚你需要将这个命令的结果输入到终端并执行它。

修复工作为我是复制的结果到剪贴板与

aws ecr get-login --region ap-southeast-2 | pbcopy

将结果粘贴到命令行并执行

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

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

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