docker 上的 Windows 服务无法启动

标签 windows powershell docker windows-container

我在 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/

相关文章:

powershell - 在 PowerShell 中提示用户输入

docker - docker 内 alpine 上的节点 Canvas

oracle - 如何在Docker上使用oracle11g?

java - 在 Windows 10 中的命令行上使用 Java 开关

c++ - 让一个窗口相信它仍然在焦点上,尽管它不是

.net - 是否可以判断哪个应用程序创建了文件?

powershell - 如何从值检索HashTable键?

windows - 谁能告诉我内核编程在 Linux 中是如何完成的,就像 Windows 中的 Windows DDK

powershell - Windows powershell语法可导入文本文件,剥离字段并将其导出到其他文件

docker - 禁止从 docker 容器访问 LAN