Windows services 对Windows服务Docker for Windows进行停靠

Windows services 对Windows服务Docker for Windows进行停靠,windows-services,docker-for-windows,Windows Services,Docker For Windows,我有一个现有的Windows服务,我想将其移动到Windows中的docker容器。我是新来的。如果有人能帮助我创建docker映像,将windows服务移动到docker中,这将非常有用。首先,下载脚本 您需要像这样编写dockerfile FROM microsoft/windowsservercore SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Silen

我有一个现有的Windows服务,我想将其移动到Windows中的docker容器。我是新来的。如果有人能帮助我创建docker映像,将windows服务移动到docker中,这将非常有用。

首先,下载脚本 您需要像这样编写dockerfile

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
然后打开powershel和文件夹并运行dockerfile

docker build .

将现有windows服务转换为在docker容器中运行相当容易。您需要先获取此脚本中提到的,然后它才能工作。它是.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”的服务名称可以是“我的Windows服务名称”或“Fred”,您需要知道这两个名称。

将Windows服务转换为控制台应用程序。并使用dotnet框架,分别为项目和容器创建docker映像。