2

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?

Idan Levi
  • 388
  • 3
  • 18
  • Is your service actually named `TestService` or `WcfService`? On startup, a service registers itself with the service controller under a particular name, and it will only start when invoked using that name. You cannot register an executable under an arbitrary service name, it must be exactly the service name it's using. (The name of the *executable* is immaterial, though.) – Jeroen Mostert May 31 '18 at 14:54
  • There is no installation specified in your docker file and hence the error message during run. So you need to use `installutil` etc step before entrypoint. In addition, your entrypoint shall not be your service executable either – Gregory Suvalian May 31 '18 at 14:56
  • @JeroenMostert Without containers, I managed to run the service under the same name on my Windows 10 machine. I tried to define a service with the service name it is being initialized in (this.ServiceName = "WcfService1";) but I still get the same error. – Idan Levi May 31 '18 at 15:00
  • @GregorySuvalian I couldn't figure out how and when to use installutil. And about the entry point.. what can I use instead? – Idan Levi May 31 '18 at 15:02
  • 1
    You could dig a little deeper and check the event log (`Get-EventLog -LogName System -Newest 10 -Source "Service Control Manager" | Select *`, look into `Application` if the service logged something itself) to see what the error actually is. A timeout suggests a naming conflict, but it could be something else. – Jeroen Mostert May 31 '18 at 15:05
  • Install Windows Server Core 1709 as VM. Run all the commands you need from console on that VM to make your service running. Then duplicate those commands in `DOCKERFILE`. You need to replace ENTRYPOINT with something other then your service executable. For example use `servicemonitor` executable from IIS Image. ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]. Replace w3svc with your service name – Gregory Suvalian May 31 '18 at 15:05
  • @JeroenMostert, your comment helped me get the answer I needed, but I can't accept this comment as an answer. Thanks! – Idan Levi Jun 03 '18 at 06:10

1 Answers1

6

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.

Idan Levi
  • 388
  • 3
  • 18