简体   繁体   English

docker 上的 Windows 服务无法启动

[英]Windows service on docker does not start

I've created a C# WCF Windows service app in VS 2017 and added Docker Support.我在 VS 2017 中创建了一个 C# WCF Windows 服务应用程序并添加了 Docker 支持。

The following Dockerfile was created:创建了以下 Dockerfile:

FROM microsoft/dotnet-framework:4.7.1-windowsservercore-1709
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["C:\\WcfService.exe"]

When I build it using docker-compose in VS I get an error:当我在 VS 中使用 docker-compose 构建它时,我收到一个错误:

Cannot start service from the command line or a debugger.无法从命令行或调试器启动服务。 A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.必须首先安装 Windows 服务(使用 installutil.exe),然后使用 ServerExplorer、Windows 服务管理工具或 NET START 命令启动。 The program '[2172] WcfService.exe' has exited with code 0 (0x0).程序“[2172] WcfService.exe”已退出,代码为 0 (0x0)。

I've opened PowerShell and typed docker ps - the container is running.我打开了 PowerShell 并输入了docker ps - 容器正在运行。 So I used New-Service command and to create "TestService".所以我使用了New-Service命令并创建了“TestService”。 When I use Get-Service to see all services, I can see it in the list in 'Stopped' mode.当我使用Get-Service查看所有服务时,我可以在“已停止”模式的列表中看到它。 When I use Start-Service TestService I get the following error:当我使用Start-Service TestService ,出现以下错误:

Start-Service : Failed to start service 'TestService (TestService)'.启动服务:无法启动服务“TestService (TestService)”。 At line:1 char:1 + Start-Service TestService + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException + FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand在 line:1 char:1 + Start-Service TestService + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController: ServiceController) [Start-Service], ServiceCommandException +fullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand

Tried to find info but nothing works.试图查找信息,但没有任何效果。 Any ideas?有任何想法吗?

Ok, so I took Jeroen's advice and dug deeper to see the event viewer.好的,所以我接受了 Jeroen 的建议并深入挖掘以查看事件查看器。 I used some filters on the 'Get-EventLog' command to get the relevant error line and stored it in a variable我在“Get-EventLog”命令上使用了一些过滤器来获取相关的错误行并将其存储在一个变量中

$A = Get-EventLog -LogName System -Newest 10 -Source "Service Control Manager" | Select *

Then, I formatted it nice using something like:然后,我使用以下内容对其进行了很好的格式化:

$A | Format-List -Property *

and got the exception.并得到了例外。

Apparently it has something to do with a C++ dll my app is using.显然它与我的应用程序使用的 C++ dll 有关。 It could be missing or the environment has trouble running it, but that's another issue which I believe I can solve.它可能丢失或环境无法运行它,但这是我相信我可以解决的另一个问题。

Hope that helps others running into similar issues.希望能帮助其他遇到类似问题的人。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM