我在Dockerfile
中使用PowerShell
作为默认外壳来完成一些任务,例如将新用户和组添加到我的容器构建中。
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
会话,或者在运行时使用 CMDoverrride
它?
尝试根据壳牌的文档在 CMD 之前添加以下内容
SHELL ["cmd", "/S", "/C"]