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


当前回答

以下命令适用于我:

sudo $(aws ecr get-login --region us-east-1 --no-include-email)

然后我运行这些命令:

sudo docker tag e9ae3c220b23(image_id) aws_account_id.dkr.ecr.region.amazonaws.com/my-web-app

sudo docker push aws_account_id.dkr.ecr.region.amazonaws.com/my-web-app

其他回答

在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

请参见故障排除页面。

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

确保您在本地运行Docker的用户就是您最终用于推送映像的用户。对我来说,使用sudo导致了这个问题。从命令中删除sudo可以解决这个问题。希望这能帮助和节省一些人的时间,没有人再犯同样愚蠢的错误。以下是输出,供您参考。

sudo docker push {your-account-id}.dkr.ecr.us-east-1.amazonaws.com/{repository-name}:{tag-name}
The push refers to repository [{your-account-id}.dkr.ecr.us-east-1.amazonaws.com/{repository-name}]
f13afaa342eb: Preparing
d01b75ce3235: Preparing
7eaa58141607: Preparing
519e8c5b2557: Preparing
15d4a3a33fec: Preparing
fdbbf41b1ab8: Waiting
4b88ecda5399: Waiting
e23a8e1e773f: Waiting
6623e2cc11cd: Waiting
no basic auth credentials

不带sudo跑步完全没问题

docker push {your-account-id}.dkr.ecr.us-east-1.amazonaws.com/{repository-name}:{tag-name}
The push refers to repository [{your-account-id}.dkr.ecr.us-east-1.amazonaws.com/{repository-name}]
f13afaa342eb: Pushed
d01b75ce3235: Pushed
7eaa58141607: Pushed
519e8c5b2557: Pushed
15d4a3a33fec: Pushed
fdbbf41b1ab8: Pushed
4b88ecda5399: Pushed
e23a8e1e773f: Pushed
6623e2cc11cd: Pushed
{tag-name}: digest: sha256:5ceaa5bf7605559582960b6d56a8eece9486ce0950bca9dd63a0dcd38a520bf0 size: 4293

如果您使用多个配置文件,并且需要登录到一个不是默认配置文件的配置文件,您需要使用此命令登录:

$(AWS_PROFILE=<YOUR PROFILE> aws ecr get-login --no-include-email --region eu-west-1)

刚刚进行了更新,从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标志