windows - Docker 推送到 AWS ECR 在 Windows : no basic

我在 Windows 上使用 docker(Docker for Windows,而不是 Docker Toolbox)和 cygwin(“git bash”)shell 中的 aws cli。我正在尝试将 docker 镜像推送到 AWS ECR - 私有(private) ECS 存储库。

无论我做什么 - 当我运行 docker push 时,我会反复得到:

no basic auth credentials

方法一

我一直按照说明运行标准命令:

$ $(aws --profile myprofile ecr get-login --region us-east-1)
Login Succeeded
$ docker tag myrepo:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo:latest
$ docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo:latest
The push refers to a repository [232097583865.dkr.ecr.us-east-1.amazonaws.com/potion]
688f61a6956d: Preparing
11908ead416e: Preparing
no basic auth credentials

没有成功。

尝试拉取显示确实,我没有访问权限:

$ docker pull 123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo
Using default tag: latest
Pulling repository 123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo
unauthorized: authentication required

但是 docker 确实认为我已经登录了:

$ docker logout https://123456789.dkr.ecr.us-east-1.amazonaws.com
Remove login credentials for https://123456789.dkr.ecr.us-east-1.amazonaws.com

# let's run again - should not be logged in now
$ docker logout https://123456789.dkr.ecr.us-east-1.amazonaws.com
Not logged in to https://123456789.dkr.ecr.us-east-1.amazonaws.com

嗯。

方法二

互联网建议剖析命令并使用旧程序登录。

基本上可以归结为这样的:

docker login -u AWS -p $(aws --profile myprofile ecr get-authorization-token --region us-east-1 --output text --query authorizationData[].authorizationToken | python -c 'import base64, sys; print base64.b64decode(sys.stdin.read())' | cut -d: -f2) https://123456789.dkr.ecr.us-east-1.amazonaws.com

这似乎也成功了,但是 docker pushpull 导致同样的失败。

其他死胡同

Windows 和 cygwin 很奇怪。所以,让我们将 docker login 命令放在一个 shell 脚本文件中,然后运行它,或者获取它。没有成功。

使用明确的访问 token 和新的凭据集生成额外的 AMI 配置文件。没有成功。

将 AWS 凭证导出为环境变量并重复该过程。没有成功。

使用令人敬畏的 aws-temp-token.sh 脚本,该脚本采用 MFA 代码并生成 session 凭据作为环境变量。没有成功(尽管该工具在其他时候可以挽救生命,所以请使用它)。

剧透警告

我最终设法解决了这个问题。不过这太令人沮丧了,我发现网上没有提到解决方案,所以写一个答案应该有望减轻一些精神上的痛苦。

最佳答案

我的一个搜索让我找到了 this answer ,虽然它与我的案例无关,但让我注意到了存储身份验证凭据的位置:docker config.json 文件。查看 here 以了解有关它及其身份验证用法的更多信息。

但是,我自己的文件在使用上述任何一种方法登录后都有这些内容:

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

对 Windows (wincred) 的明确提及引起了我的注意。阅读更多内容后,似乎 Windows 上的 docker 使用 helper credential store 可能比在文件系统上将凭据存储为纯文本更好(它通常存储为 base64,希腊语是“纯文本”)。

但是 - 当我手动编辑此文件以直接包含身份验证 token 时,解决方案出现了。

我使用此命令生成了我的身份验证 token (为简洁起见,缩短了输出):

$ aws --profile myprofile ecr get-authorization-token --region us-east-1 --output text --query authorizationData[].authorizationToken
jFHNnVxZ............Vqc==

编辑~/.docker/config.json后,看起来是这样的:

{
    "auths": {
        "https://123456789.dkr.ecr.us-east-1.amazonaws.com": {
            "auth": "jFHNnVxZ............Vqc=="
        }
    }
}

有了这个,推送终于成功了:

$ docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo:latest
The push refers to a repository [123456789.dkr.ecr.us-east-1.amazonaws.com/myrepo]
61a69688f56d: Pushed
11ad4908e16e: Pushed
myrepo: digest: sha256:20c0f3......82aa19 size: 42162

一切都好起来了。

关于windows - Docker 推送到 AWS ECR 在 Windows : no basic auth credentials 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38294628/

相关文章:

amazon-web-services - 将 AWS EFS 与 Docker 结合使用

dns - 如何让 docker 容器与 sshuttle 一起工作?

docker - Jenkins错误的卷权限

spring - Docker Compose + Spring Boot + Postgres 连

php - 使用 docker-compose 保持容器事件并链接

docker - 证书是如何从 super 账本中 hfc-key-store 中真实的 fabri

bash - 如何在 ENTRYPOINT 等待 postgres 启动?

docker - 如何基于现有镜像创建新的 docker 镜像?

docker - 如何使用 Jenkins 管道在 docker 容器中安装 Jenkins 工作区

docker - 如何将端口从一个 docker 容器转发到另一个?