我正在嘗試在容器中運行 Web 應用程式。實體化容器時,我需要運行一個 powershell 腳本。該腳本將使用環境變數值修改組態檔。為此,我在我的 docker 檔案中添加了一個“ENTRYPOINT”。
碼頭工人檔案
FROM mcr.microsoft.com/windows/servercore/iis:latest
# Copy powershell scripts
COPY scripts/ scripts/
#update values
ENTRYPOINT ["powershell", "C:\\scripts\\updateconfig.ps1"]
當我使用“docker run”命令實體化一個容器實體時。它確實創建了一個容器并執行該 powershell 腳本,但隨后它停止了該容器。我知道它在完成執行時停止了該容器。
powershell 腳本 (updateconfig.ps1)
((Get-Content -Path ".\scripts\appsettings.json" -Raw) -replace '{{SQLSERVER}}', [System.Environment]::GetEnvironmentVariable('SQL_SERVER')) |
Set-Content -Path ".\scripts\appsettings.json"
在經歷了這么多 stackoverflow 執行緒之后,我嘗試了一些東西,但沒有一個能給我想要的結果。我嘗試過 CMD,而不是 EntryPoint,但最終出現錯誤
> CMD powershell "C:\\scripts\\printvar.ps1"
錯誤:
Service 'w3svc' has been stopped
APPCMD failed with error code 4312
Failed to update IIS configuration
以下做同樣的事情,執行腳本并停止容器
> ENTRYPOINT ["powershell", "-NoExit", "-File", "/scripts/printvar.ps1"]
如何連續運行容器實體?
uj5u.com熱心網友回復:
“服務監視器”是 IIS 映像中的默認入口點。當我使用它作為基礎影像時,我實際上是用一個 powershell 腳本覆寫了默認入口點。我將此添加到我的 powershell 腳本中,現在容器正在連續運行
Invoke-Expression "& `"C:\\ServiceMonitor.exe`" w3svc"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495224.html