How to make a dockerfile for running Windows Services

To run a Windows Service into Docker for Windows, you have to take some actions…

First you need to create the service. Use the sc.exe command. Make your service starting as auto. It will be running automatically.

If you need to start as an administrator to have admin privileges, use the sc sdset command:


It’s weird and ugly but it works !

A tip & trick: ask docker to start an OS image that ships IIS to be able to see your custom log files. Else, you can’t see what’s happening…

If you run your docker image in Azure Container Instance, be carefull that your image need to be a Windows Server 1609…

So I start theses images in my various dockerfiles:

  • FROM microsoft/dotnet-framework:4.6.2-runtime-windowsservercore-ltsc2016
  • FROM microsoft/aspnet:4.6.2-windowsservercore-ltsc2016

My log file is written in c:\temp\logs so I make a custom WebApp on tis folder:

RUN powershell.exe New-WebVirtualDirectory -Site ‘Default Web Site’ -Name Logs -PhysicalPath ‘c:\temp\logs’

With this kind of dockerfile, I can see the log file of my Windows Service and communicate with him:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: