首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对接Windows Service Docker for Windows

对接Windows Service Docker for Windows
EN

Stack Overflow用户
提问于 2018-06-07 20:34:15
回答 2查看 2.6K关注 0票数 2

我有一个现有的windows服务,我想要将其移动到Windows中的停靠容器。我是个新手。如果有人能帮助我如何创建docker镜像来将windows服务移动到docker中,这将是有帮助的。

EN

回答 2

Stack Overflow用户

发布于 2018-09-25 22:45:55

首先,下载您需要编写的wait-service脚本,如下所示

代码语言:javascript
复制
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和文件夹并运行

代码语言:javascript
复制
docker build .
票数 3
EN

Stack Overflow用户

发布于 2020-04-02 08:17:10

将现有windows服务转换为在docker容器中运行相当容易。您需要先获取此脚本中提到的installutil.exe,然后它才能工作。它是.NET框架的一部分。如果您的服务没有记录到事件查看器中,则不需要这里的最后9行代码。

代码语言:javascript
复制
# 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‘的服务名称,你需要知道这两个名称。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50741364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档