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


当前回答

Make sure you have created the ECR registry first. Then as per the ECR Push Command Instructions, cut and paste the following commands Execute the docker login command (eval on Mac/Linux skips the cut-and-paste) eval $(aws ecr get-login --region us-east-1) add --profile if you use multiple AWS Accounts eval $(aws ecr get-login --region us-east-1 --profile your-profile) docker build -t image-name . docker tag image-name:latest ############.dkr.ecr.us-east-1.amazonaws.com/image-name:latest docker push ############.dkr.ecr.us-east-1.amazonaws.com/image-name:latest

如果出现错误,请确保再次运行所有命令!使用aws ecr get-login获得的凭据是临时的,将会过期。

其他回答

如果为了CI/CD目的隔离AWS帐户,并且在多个AWS帐户之间共享一个ECR存储库,则可能需要更改~/.docker/配置。手动json。

假设你有这些设置:

ECR由AWS帐户ID 00000000000000拥有 CI服务器属于AWS帐户ID 99999999999999

如果您在CI服务器中调用aws ecr get-login——region us-west-2 | bash, docker将在~/.docker/config.json中生成临时凭证。

{
  "auths": {
    "https://99999999999999.dkr.ecr.us-west-2.amazonaws.com": {
      "auth": "long-token.."
    }
  }
}

但是您希望指向ECR的帐户,因此需要更改主机名。

{
  "auths": {
    "https://00000000000000.dkr.ecr.us-west-2.amazonaws.com": {
      "auth": "long-token.."
    }
  }
}

注意,这种情况取决于您如何形成IAM用户/策略以允许ECR访问。

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

这个错误消息来自docker,它不一定与AWS有关,因为我在不使用AWS时也得到了相同的错误…它只是说docker没有从它碰巧使用的任何认证源获得授权

在我的例子中,在测试中我删除了目录~/。Docker得到了这个错误…在我反弹了我的本地docker注册表后,docker push就没问题了

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

我也有这个问题。发生在我身上的事情是我忘记运行在我运行后返回给我的命令

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

该命令返回一个大blob,其中包括docker登录命令!我没有意识到。它应该返回如下内容:

docker login -u AWS -p <your_token_which_is_massive> -e none <your_aws_url>

复制并粘贴这个命令,然后运行docker push命令,看起来像这样:

docker push 8888888.blah.blah.ap-southwest-1.amazonaws.com/dockerfilename