[英]How to execute PowerShell script in Windows-container under Docker?
Below is my entrypoint.ps1
( PowerShell -script):下面是我的entrypoint.ps1
( PowerShell -script):
Set-Location -Path C:\nginx
& "C:\nginx\Configure-Nginx.ps1"
& "C:\nginx\nginx.exe"
I need to my Configure-Nginx.ps1
and node.exe
were executed on docker run
so I've put an entrypoint to my Dockerfile
:我需要在docker run
时执行我的Configure-Nginx.ps1
和node.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"]
However my container begins to restart each minute... Well, I've decided there is a some error in the script then I run this image manually with --entrypoint powershell
and executed my script in the console directly: .\entrypoint.ps1
.但是我的容器每分钟都开始重新启动......好吧,我已经确定脚本中有一些错误然后我使用--entrypoint powershell
手动运行此映像并直接在控制台中执行我的脚本: .\entrypoint.ps1
. The script was frozen (cuz nginx
was launched) and I could connect to my container from web-browser on the host machine... So everything works!脚本被冻结(因为nginx
已启动),我可以从主机上的网络浏览器连接到我的容器......所以一切正常! Then why doesn't it work if I call my entrypoint from Dockerfile
?那么,如果我从Dockerfile
调用我的入口点,为什么它不起作用? What's difference?有什么区别? Maybe someone has met a similar problem...也许有人遇到过类似的问题......
PS The container is based on mcr.microsoft.com/windows/servercore:1809-KB5003171
with PowerShell v5.1.17763.1852 PS容器基于mcr.microsoft.com/windows/servercore:1809-KB5003171
和PowerShell v5.1.17763.1852
Firs make sure the script is available under the container root:首先确保脚本在容器根目录下可用:
COPY entrypoint.ps1 /entrypoint.ps1
Then execute it either by -Command
or -File
:然后通过-Command
或-File
执行它:
ENTRYPOINT ["pwsh", "-Command", "/entrypoint.ps1"]
ENTRYPOINT ["pwsh", "-File","/entrypoint.ps1"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.