Skip to main content
 首页 » 编程设计

powershell之DockerFile调用安装MSI

2025年05月04日285soundcode

我很难通过Dockerfile安装MSI。我的Dockerfile:

FROM microsoft/windowsservercore:latest 
 
RUN mkdir C:\temp  
RUN mkdir C:\temp\msis 
 
COPY . "C:/temp/msis" 
RUN powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.msi" -ArgumentList  "/qn" -PassThru | Wait-Process} 

当通过以下方式运行docker build时:
docker build -t myTools . 

我收到以下错误:
Step 7/7 : RUN powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.msi" -ArgumentList  "/qn" -PassThru | Wait-Process} 
---> Running in d6f9f65d96a9 
'Wait-Process}' is not recognized as an internal or external command,operable program or batch file. 

如果我在不运行RUN步骤的情况下构建了容器,并通过 -it将自己附加到正在运行的容器中,然后粘贴 powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.msi" -ArgumentList "/qn" -PassThru | Wait-Process}命令,则MSI将正确安装。

有谁知道这种失败会发生吗?

谢谢

请您参考如下方法:

可能是PowerShell分析问题。

尝试以下两行,而不是最后一行:

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] 
 
RUN Start-Process 'C:\\temp\\msis\\mySetup.msi' '/qn' -PassThru | Wait-Process; 

之后,您可以根据需要还原到cmd.exe:
SHELL ["cmd", "/C"]