gpt4 book ai didi

docker - Docker化Windows服务

转载 作者:行者123 更新时间:2023-12-02 19:20:13 25 4
gpt4 key购买 nike

我是Docker的新手,我有一个包含一组Windows服务(.NET)的应用程序。我想将其运行到docker容器中。我该怎么办 ?

最佳答案

我已使用以下Dockerfile将Windows服务成功放入docker容器中。将MyWindowsServiceName替换为您自己的Windows服务的名称。

# escape=\

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-1709

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY ["MyWindowsServiceName/bin/Release/", "/Service/"]

WORKDIR "C:/Service/"

RUN "C:/Service/InstallUtil.exe" /LogToConsole=true /ShowCallStack MyWindowsServiceName.exe; \
Set-Service -Name "\"MyWindowsServiceName\"" -StartupType Automatic; \
Set-ItemProperty "\"Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyWindowsServiceName\"" -Name AllowRemoteConnection -Value 1

ENTRYPOINT ["powershell"]
CMD Start-Service \""MyWindowsServiceName\""; \
Get-EventLog -LogName System -After (Get-Date).AddHours(-1) | Format-List ;\
$idx = (get-eventlog -LogName System -Newest 1).Index; \
while ($true) \
{; \
start-sleep -Seconds 1; \
$idx2 = (Get-EventLog -LogName System -newest 1).index; \
get-eventlog -logname system -newest ($idx2 - $idx) | sort index | Format-List; \
$idx = $idx2; \
}

注1 :我的Windows服务记录到Windows事件系统。因此,根据Docker约定,该文件最后包含一些不错的代码,可将EventLog信息打印到控制台。您可能需要也可能不需要这部分来提供自己的服务。如果不是,则仅使用第一行减去“\”。

注2 :Windows服务的名称可能与其可执行文件名称不同。也就是说,“MyWindowsServiceName.exe”的服务名称可能是“我的Windows服务名称”或“Fred”,您需要同时了解两者。

关于docker - Docker化Windows服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60541158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com