我有一个现有的windows服务,我想要将其移动到Windows中的停靠容器。我是个新手。如果有人能帮助我如何创建docker镜像来将windows服务移动到docker中,这将是有帮助的。
发布于 2018-09-25 22:45:55
首先,下载您需要编写的wait-service脚本,如下所示
FROM microsoft/windowsservercore
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /
COPY Wait-Service.ps1 service.exe ./
RUN install_you_service
CMD c:\Wait-Service.ps1 -ServiceName 'service' -AllowServiceRestart然后用dockerfile打开powershel和文件夹并运行
docker build .发布于 2020-04-02 08:17:10
将现有windows服务转换为在docker容器中运行相当容易。您需要先获取此脚本中提到的installutil.exe,然后它才能工作。它是.NET框架的一部分。如果您的服务没有记录到事件查看器中,则不需要这里的最后9行代码。
# 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; \
}注释:windows服务的名称可能与其可执行文件的名称不同。也就是说,'MyWindowsServiceName.exe‘可以有一个'My Windows service Name’或'Fred‘的服务名称,你需要知道这两个名称。
https://stackoverflow.com/questions/50741364
复制相似问题