繁体   English   中英

如何在 Docker 下的 Windows 容器中执行 PowerShell 脚本?

[英]How to execute PowerShell script in Windows-container under Docker?

下面是我的entrypoint.ps1PowerShell -script):

Set-Location -Path C:\nginx
& "C:\nginx\Configure-Nginx.ps1"
& "C:\nginx\nginx.exe"

我需要在docker run时执行我的Configure-Nginx.ps1node.exe ,所以我在Dockerfile中放置了一个入口点:

FROM nginx 
# nginx is a custom image that's based on mcr.microsoft.com/windows/servercore:1809-KB5003171
COPY entrypoint.ps1 ./
COPY install/Configure-Nginx.ps1 /nginx/Configure-Nginx.ps1
ENTRYPOINT ["powershell", "entrypoint.ps1"]

但是我的容器每分钟都开始重新启动......好吧,我已经确定脚本中有一些错误然后我使用--entrypoint powershell手动运行此映像并直接在控制台中执行我的脚本: .\entrypoint.ps1 . 脚本被冻结(因为nginx已启动),我可以从主机上的网络浏览器连接到我的容器......所以一切正常! 那么,如果我从Dockerfile调用我的入口点,为什么它不起作用? 有什么区别? 也许有人遇到过类似的问题......

PS容器基于mcr.microsoft.com/windows/servercore:1809-KB5003171PowerShell v5.1.17763.1852

首先确保脚本在容器根目录下可用:

COPY entrypoint.ps1 /entrypoint.ps1

然后通过-Command-File执行它:

ENTRYPOINT ["pwsh", "-Command", "/entrypoint.ps1"]
ENTRYPOINT ["pwsh", "-File","/entrypoint.ps1"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM