我正在尝试将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,请使用以下命令

aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <ecr-repo-full-path>

例子

aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 607348619222.dkr.ecr.ap-south-1.amazonaws.com

其他回答

这只是为了防止有人像我一样从来没有读过F手册 我遵循了上面建议的所有步骤,比如

aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.eu-west-1.amazonaws.com

而且总是没有基本的认证证书 我创建了一个名为

123456789.dkr.ecr.eu-west-1.amazonaws.com/my.registry.com/namespace 

并试图推广一个叫alpine:latest的图片

123456789.dkr.ecr.eu-west-1.amazonaws.com/my.registry.com/namespace/alpine:latest
2c6e8b76de: Preparing
9d4cb0c1e9: Preparing
1ca55f6ab4: Preparing
b6fd41c05e: Waiting
ad44a79b33: Waiting
2ce3c1888d: Waiting
no basic auth credentials   

愚蠢的错误在我的代表,因为我必须创建一个注册表在ecr使用完整的容器路径。 我使用完整的容器路径创建了一个新的注册中心,而不是在名称空间上结束

123456789.dkr.ecr.eu-west-1.amazonaws.com/my.registry.com/namespace/alpine

又低又快

123456789.dkr.ecr.eu-west-1.amazonaws.com/my.registry.com/namespace/alpine:latest 
The push refers to repository [123456789.dkr.ecr.eu-west-1.amazonaws.com/my.registry.com/namespace/alpine]
0c8667b5b: Pushed
730460948: Pushed
1.0: digest: sha256:e1f814f3818efea45267ebfb4918088a26a18c size: 7

工作很好

即使没有打开权限,这也应该可以工作。请参阅文档:私有注册中心身份验证。

[编辑:实际上,我在做第二次测试时也遇到了权限问题。参见Docker推送到AWS ECR私有回购失败,JSON格式不正确)。

然而,我也遇到了同样的问题;我不知道为什么,但我成功地使用了文档中描述的get-authorization-token的更冗长的认证机制

AWS CLI和Docker版本:

$ aws --version
aws-cli/1.9.17 Python/2.7.6 Linux/3.16.0-38-generic botocore/1.3.17
$ docker --version
Docker version 1.9.1, build a34a1d5

获取认证令牌('docker密码')。

aws ecr get-authorization-token --region us-east-1 --output text \
    --query authorizationData[].authorizationToken | base64 -d | cut -d: -f2

注:My ~/。aws/config指定了一个不同的默认区域,所以我需要显式地设置——region us-east-1。

交互式登录(将############更改为您的AWS帐户id):

docker login -u AWS https://############.dkr.ecr.us-east-1.amazonaws.com/
password: <paste the very long password from above>
email: <I left this blank>

推送一个图像(假设你已经做了一个docker图像测试):

docker tag test:latest ############.dkr.ecr.us-east-1.amazonaws.com/test:latest
docker push ############.dkr.ecr.us-east-1.amazonaws.com/test:latest
The push refers to a repository [910732017890.dkr.ecr.us-east-1.amazonaws.com/test] (len: 1)
d5122f58a2e1: Pushed 
7bddbca3b908: Pushed 
latest: digest: sha256:bc0b521fd398bd1a2ef58a289dcb910334608723fd570e7bddb36eacd0060363 size: 4378

如果ecr登录失败,通常会抛出此错误。我使用的是windows系统,我在管理员模式下使用“Powershell”首先登录到ecr。

Invoke-Expression $(aws ecr get-login --no-include-email)

这应该会输出“Login succeeded”。

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": {}
    },

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

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