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


当前回答

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

其他回答

Mac OSX

确保您的“auths”密钥与您的凭据存储密钥完全匹配

检查docker配置:

猫~ / .docker / json

结果:样本

{
    "auths": {
        "https://55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/19.03.5 (darwin)"
    },
    "credsStore": "osxkeychain"
}

注意,“auths”值是一个空对象,docker正在使用一个凭据存储“osxkeychain”。

打开Mac的“Keychain Access”应用程序,找到名称“Docker Credentials”

注意Where:字段

确保认证输入~/.docker/config。json匹配Keychain Access中的Where:字段。

如果认证者输入~/.docker/config. conf。在keychain中:字段,你可能会得到Login Succeeded from docker Login…但是仍然得到 错误:服务“web”未能构建:获得https://55511155511.dkr.ecr.us-east-1.amazonaws.com/v2/path/to/image/latest:没有基本的身份验证凭据,当你试图拉。

在我的例子中,我需要添加https://

原始

    "auths": {
        "55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },

固定

    "auths": {
        "https://55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },

更新

由于AWS CLI版本2 - AWS ecr get-login已弃用,正确的方法是AWS ecr get-login-password。

因此,正确的最新答案如下: docker login -u AWS -p $(AWS ecr get-login-password——region us-east-1) xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com

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

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

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

我在OSX上运行时也遇到了这个问题。我看到了Oliver Salzburg的响应,并检查了我的~/.docker/config.json。它里面有来自我拥有的不同AWS帐户的多个授权凭证。我删除了该文件,再次运行get-login后,它工作了。