我在 VS 2017 中创建了一个 C# WCF Windows 服务应用程序并添加了 Docker 支持。
创建了以下 Dockerfile:
FROM microsoft/dotnet-framework:4.7.1-windowsservercore-1709
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["C:\\WcfService.exe"]
当我在 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. The program '[2172] WcfService.exe' has exited with code 0 (0x0).
我打开了 PowerShell 并输入了 docker ps
- 容器正在运行。
所以我使用了 New-Service
命令并创建了“TestService”。
当我使用 Get-Service
查看所有服务时,我可以在“已停止”模式的列表中看到它。
当我使用 Start-Service TestService
时,出现以下错误:
Start-Service : Failed to start service '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
试图查找信息,但无济于事。有什么想法吗?
最佳答案
好的,所以我采纳了 Jeroen 的建议并深入挖掘以查看事件查看器。我在“Get-EventLog”命令上使用了一些过滤器来获取相关的错误行并将其存储在变量中
$A = Get-EventLog -LogName System -Newest 10 -Source“服务控制管理器”|选择 *
然后,我用类似的东西格式化它:
$A | Format-List -Property *
并得到异常。
显然它与我的应用程序正在使用的 C++ dll 有关。它可能丢失或环境无法运行它,但这是我相信我可以解决的另一个问题。
希望能帮助其他遇到类似问题的人。谢谢。
关于docker 上的 Windows 服务无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50627116/