我在使用Powershell对AWS运行docker login时遇到问题。
更具体地说,我是在K8S容器(在powershell集群内)上的Jenkins管道上使用powershell步骤运行它的,如下所示
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,所以在EC2上启动容器时,绑定到底层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"有什么问题吗?
发布于 2021-01-12 16:19:56
我设法解决了。
问题原因
看来,这个问题与在Jenkins上运行powershell时如何管理管道有关,而且由于某些原因(我还没有弄清楚),在令牌之前添加了一个新行,这样就可以代替
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'https://stackoverflow.com/questions/65576285
复制相似问题