docker - Docker 容器中的 Windows 服务
问题描述
我正在研究可能的应用程序 dockerisation。该应用程序包括多个 Windows 服务 (.NET WCF)。我还没有尝试为 Windows 服务创建一个 dockerfile。但是,如果有人可以为我提供一些指示是否有效,我们将不胜感激。
解决方案
在您的情况下,我可能会为每个 Windows 服务创建一个图像。
以下 Dockerfile 非常适合我将 Windows 服务构建到 docker 映像中。
您的所有服务文件都需要位于 docker 上下文的“Installs”文件夹中,以及 InstallUtils.exe 文件的副本(来自 .NET / Visual Studio)。
# escape=\
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-1709
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
COPY ["Installs/", "/Service/"]
WORKDIR "C:/Service/"
RUN "C:/Service/InstallUtil.exe" /LogToConsole=true /ShowCallStack SmartFormsToWorkInjuryReportingService.exe; \
Set-Service -Name "\"My Windows Service Name\"" -StartupType Automatic; \
Set-ItemProperty "\"Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\My Windows Service Name\"" -Name AllowRemoteConnection -Value 1
ENTRYPOINT ["powershell"]
CMD Start-Service \""My Windows Service Name\""; \
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; \
}
仅供参考,然后您可以通过以下方式运行该服务:
docker run --rm --net=MyNet --platform=windows -p 80:80 --name MyWindowsServiceContainer mywindowsserviceimage
推荐阅读
- machine-learning - NLP:从 PDF 文件中提取特定领域的数据
- c# - c#中原始参数为null时如何指定自动使用Convert.DBNull作为sql参数值?
- ios - 打印结果后执行 Alamofire 请求
- java - java - 如何使用Java按键除以点来获取嵌套值?
- c++ - 访问者模式适用于 shared_ptr 还是原始指针?
- jquery - 4 col 在引导程序中逐一滚动
- laravel - 如何防止请求被缓存以用于 LANGUAGE SWITCH 路由 Laravel Spatie responsecache
- git - 在 Windows 10 下使用 PhpStorm 2018 的 PHP CS Fixer 出现问题
- php - CodeIgniter 出现数据库错误,为什么要进行身份插入?
- java - JAXB 的 XML 注释适用于 JDK8,但抛出 MessageBodyWriter not found with JDK11