我正在尝试将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中删除了get-login,而是使用get-login-password:

sudo docker login -u AWS -p $(aws ecr get-login-password --region <region> - 
-profile <profile>) <account id>.dkr.ecr.eu-north-1.amazonaws.com 

如果使用默认凭证,不要忘记删除——profile标志

其他回答

有一个非常简单的方法可以将docker镜像推送到ECR: Amazon ECR docker Credential Helper。只需根据提供的指南安装它,更新您的~/.docker/config。Json格式如下:

{
    "credsStore": "ecr-login"
}

你将能够推/拉你的图像没有docker登录。

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

## 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

试一试:

eval $(aws ecr get-login --no-include-email | sed 's|https://||')

前推。

如果你运行$(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注册表。