簡體   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