gpt4 book ai didi

powershell - 使用 PowerShell 作为默认 Shell,但在批处理文件运行时将其丢弃

转载 作者:行者123 更新时间:2023-12-02 19:25:54 24 4
gpt4 key购买 nike

我用 PowerShell作为我在 Dockerfile 中的默认 shell完成一些任务,例如将新用户和组添加到我的容器构建中。

DockerFile(相关)

SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]
RUN New-LocalUser -Name "testuser" -Password (ConvertTo-SecureString -AsPlainText "CrackPassword!" -Force) -FullName "Test.User" -Description "LocalAdministrator"
RUN Add-LocalGroupMember -Group administrators -Member testuser -Verbose
RUN "C:/Windows/Microsoft.NET/Framework64/v4.0.30319/InstallUtil.exe" /username=.\testuser /password=CrackPassword! /LogToConsole=true /ShowCallStack TestDockerService.exe

在同一个 DockerFile ,我指定一个CMD来运行一个批处理文件时 Docker container运行。
COPY testbat.bat /testbat.bat
CMD testbat.bat && cmd

图像构建良好,但 Docker Run不起作用,提示:
At line:1 char:111
+ ... rence = 'Continue'; $verbosePreference='Continue'; testbat.bat && cmd
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : InvalidEndOfLine

我猜想在 SHELL 中运行 CMD 存在问题,一些快速研究表明可能是这样......

有什么办法可以关闭 SHELL session 调用,或 overrride它在运行时使用 CMD 吗?

最佳答案

尝试根据 doc for Shell 在 CMD 前添加以下内容

SHELL ["cmd", "/S", "/C"]

关于powershell - 使用 PowerShell 作为默认 Shell,但在批处理文件运行时将其丢弃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56218901/

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