Search code examples
windowspowershelldockerwindows-container

Windows service on docker does not start


I've created a C# WCF Windows service app in VS 2017 and added Docker Support.

The following Dockerfile was created:

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:

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).

I've opened PowerShell and typed docker ps - the container is running. So I used New-Service command and to create "TestService". When I use Get-Service to see all services, I can see it in the list in 'Stopped' mode. When I use Start-Service TestService I get the following error:

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

Tried to find info but nothing works. Any ideas?


Solution

  • Ok, so I took Jeroen's advice and dug deeper to see the event viewer. I used some filters on the 'Get-EventLog' command to get the relevant error line and stored it in a variable

    $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. 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.