11

I am trying to build a Windows Container based Micro-Service on Server 2016 CTP5 using .net 4.5.

In the non-container world, I am using a console app deployed as a Windows Service that subscribes to a queue and does its work.

In a container, I can just run the console app and it seems to run just fine. Is there a need to install it as a Windows Service?

TalMcMahon
  • 159
  • 2
  • 10
  • If it runs just fine there's no need to install it as a windows service. This goes for everything. – Bob Brinks Sep 26 '16 at 14:38
  • You should probably describe what requirements you have? And how that relates to your app running as a service. Also stackoverflow might not be the place for this. You should post your more complete question on http://superuser.com/tour. – Bob Brinks Sep 26 '16 at 14:40
  • I guess I thought I had expressed what my requirements were. I am running a microservice as a traditional Windows Service on a traditional Windows server (2012). I am trying to move it to a Windows container. – TalMcMahon Sep 26 '16 at 19:37
  • 1
    Also, just curious how at all, this is a superuser question? – TalMcMahon Sep 26 '16 at 19:42
  • It's about virtualization and running services not about programming – Bob Brinks Sep 27 '16 at 09:12
  • Maybe is it just semantics, but I am programming the services. – TalMcMahon Sep 27 '16 at 12:19
  • Yes but your question is not about the programming of the services. – Bob Brinks Sep 27 '16 at 13:28
  • @TalMcMahon You mentioned you are subscribing to queue is it MSMQ? If yes, how were you able to connect to HOST MSMQ in a container? – Sujit Singh Feb 20 '19 at 05:56
  • I'm trying to convert a Windows Service to a console application to run it on AKS, listening to a queue, but the container exits immediately after the console finishes. That is, it doesn't keep listening, it doesn't run continuously. How did you do that? – Pine Code Nov 15 '21 at 10:59

1 Answers1

19

No, you don't want to install it as a service. When you run an application in a container, Docker monitors the active process in the container. If the active process stops, the container exits. So you should run your app in the foreground, and let Docker put the container in the background (by starting it with docker run -d).

An exception is where the existing platform is already a Windows Service - e.g. the microsoft/iis image. IIS is running in the background in the container, so you need to start another process to keep the container running - which is why you see IIS containers started like this:

docker run -d -p 80:80 microsoft/iis ping -t localhost

The ping command keeps the container running, while the IIS service actually responds to requests. This is not ideal though, Docker is monitoring ping so if the IIS service stops the container keeps running.

Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • Great thats what I was sensing but needed to sniff test it. – TalMcMahon Sep 26 '16 at 17:38
  • 5
    Just as a side note: In the current microsoft/iis image, the default entry point is "C:\ServiceMonitor.exe w3svc" and if you run this image without any parameter, this ServiceMonitor will keep it running. So even if it is not the "way to go" with Docker to use Windows services, this might be a workaround if it's really needed. – Tobias Mar 01 '17 at 14:00