gpt4 book ai didi

ECR 上的 Docker 登录失败,并在 Jenkins 的 Powershell 上出现 400 Bad Request

转载 作者:行者123 更新时间:2023-12-05 00:44:49 24 4
gpt4 key购买 nike

我在运行 docker login 时遇到问题使用 Powershell 针对 AWS ECR。
更具体地说,我使用 powershell 从 Windows 容器(在 K8S 集群内)上的 Jenkins 管道运行它。步骤如下

powershell "aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin ****.dkr.ecr.eu-central-1.amazonaws.com"

但它失败并出现以下错误:

09:24:32  At C:\Jenkins\agent\workspace\test\awsIamRole-Test@tmp\durable-e2ffd0da\powershellWrapper.ps1:3 char:1
09:24:32 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
09:24:32 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
09:24:32 + CategoryInfo : NotSpecified: (Error response ...400 Bad Request :String) [], RemoteException
09:24:32 + FullyQualifiedErrorId : NativeCommandError

奇怪的行为是,如果我在容器上(在我的本地机器和集群上)手动运行命令一切正常并且登录成功。下面是容器的 Dockerfile。

# escape=`
FROM mcr.microsoft.com/windows/servercore:1809

SHELL ["powershell"]

RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install jq docker -y
RUN choco install awscli --version=2.1.15 -y

由于容器在 EC2 实例上运行,并且我需要在容器内运行 Docker,因此我在 K8S 上启动容器时绑定(bind)到底层 EC2 机器的 Docker 套接字,如下所示(它从管道中的 docker ps 开始工作显示正确的结果)。

  - image: "****.dkr.ecr.eu-central-1.amazonaws.com/jenkins-container-templates/docker-awscli2-windows:latest"
name: "docker-awscli2-windows"
tty: true
volumeMounts:
- mountPath: "\\\\.\\pipe\\docker_engine"
name: "docker-pipe"
volumes:
- hostPath:
path: "\\\\.\\pipe\\docker_engine"
name: "docker-pipe"

可能是什么问题?

最佳答案

我设法解决了。

问题原因

似乎问题与在 Jenkins 上运行 powershell 时如何管理管道有关,并且由于某种原因(我还没有弄清楚),在 token 之前添加了一个新行,以便代替

token

命令的第二部分作为输入


token

它可能会像根本没有输入一样处理它,并且 --password-stdin 标志使其失败并显示 BadRequest 状态。

解决方法

由于我无法删除此新行,因此我使用了解决方法

powershell 'docker login --username AWS -p $(aws ecr get-login-password --region eu-central-1 ) ****.dkr.ecr.eu-central-1.amazonaws.com'

关于ECR 上的 Docker 登录失败,并在 Jenkins 的 Powershell 上出现 400 Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65576285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com