docker - 对 Windows 服务进行 Docker 化
问题描述
我是 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”,您需要同时知道这两个名称。
推荐阅读
- javascript - 点击时图片不显示在灯箱模块中
- javascript - JS puppeteer 使用 for 循环遍历链接
- vue.js - 我有一个 vue 组件不呈现数据的问题
- javascript - 在 forEach 循环 javascript 中创建对象时出现问题
- node.js - Zookeeper getChildren 事件只触发一次
- image - 为什么 `cv2.threshold` 只需要灰度图像?
- netbeans - 带有 MAMP 问题的 NetBeans Xdebug 路径
- swift - 在 Swift 中将 CoreData 导出为 CSV
- xml - 使用 XML 命名空间的不太复杂的 XPath 表达式
- java - 如何将属性文件注入环境 bean?