在 Azure 应用服务中的容器启动时启动 Powershell 脚本

RMD*_*RMD 11 docker azure-appservice

我正在尝试使用 Azure 应用服务容器来托管 Azure DevOps Pipeline 代理。我的代理使用 Docker Desktop 在本地运行得很好,但当我将映像发布到应用服务时,启动命令永远不会执行。我被迫在容器中获取控制台并手动运行 powershell 脚本,然后该脚本将按预期工作。

这是我的泊坞窗文件:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Install-PackageProvider -Name NuGet -Force
RUN powershell Install-Module PowershellGet -Force
RUN powershell Install-Module -Name Az -Repository PSGallery -Force
RUN powershell Install-Module -Name Az.Tools.Migration -Repository PSGallery -Force
RUN powershell Enable-AzureRMAlias
WORKDIR /azp
COPY start.ps1 .
CMD powershell "c:\azp\start.ps1"
Run Code Online (Sandbox Code Playgroud)

部署中心日志没有显示任何错误。就好像 CMD 从未运行过一样。

小智 1

请更换 powershell CMD 行如下 -

CMD ["powershell.exe", "-File", "c:\azp\start.ps1"]
Run Code Online (Sandbox Code Playgroud)

如果 PATH 中不存在该 exe,最好使用该 exe 的完整路径。

还可以使用workdir,如下所示 -

FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Install-PackageProvider -Name NuGet -Force
RUN powershell Install-Module PowershellGet -Force
RUN powershell Install-Module -Name Az -Repository PSGallery -Force
RUN powershell Install-Module -Name Az.Tools.Migration -Repository PSGallery -Force
RUN powershell Enable-AzureRMAlias
WORKDIR c:\azp
COPY start.ps1 .
CMD ["powershell.exe", "-File", "c:\azp\start.ps1"]
Run Code Online (Sandbox Code Playgroud)