Windows Service Application Dockerize

Hi,

I have a Visual Studio 2012 Solution and there is a project inside it and this project is a windows service.
Project’s Target Framework: .Net Framework 4

DOCKERFILE INCLUDES:

FROM microsoft/dotnet:1.1-sdk
#FROM microsoft/dotnet-framework:4

Setting Home Directory for application

WORKDIR /app

Note: Install .Net 4 Targeting Pack

RUN Invoke-WebRequest -Uri “http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe” -OutFile “dotNetFx40_Full_x86_x64.exe” -UseBasicParsing
RUN .\dotNetFx40_Full_x86_x64.exe /q /norestart

copy csproj and restore as distinct layers

COPY TEST.csproj .
RUN dotnet restore

RUN dotnet publish -c Release -o out

EXPOSE 15166

ENTRYPOINT [“dotnet”, “bin\Debug\TEST.exe”]

ERROR MESSAGE IS:
Step 4/7 : RUN .\dotNetFx40_Full_x86_x64.exe /q /norestart
—> Running in ff8T2KK2161f
The command ‘powershell -Command $ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’; .\dotNetFx40_Full_x86_x64.exe /q /norestart’ returned a non-zero code: 1

MY DOCKER IMAGES ARE:
microsoft/aspnetcore-build
microsoft/dotnet
microsoft/dotnet
hello-world
microsoft/dotnet-framework
microsoft/windowsservercore

How shall I proceed to solve this error?

Best Regards,
Bahadir

did you able to dockerize the window service application?

The following dockerfile works well for me to put Windows Services into a docker image. All the files for your service, along with a copy of InstallUtil.exe need to be in the ‘Installs’ folder.

# escape=\

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-1709

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY ["Installs/", "/Service/"]

WORKDIR "C:/Service/"

RUN "C:/Service/InstallUtil.exe" /LogToConsole=true /ShowCallStack SmartFormsToWorkInjuryReportingService.exe; \
    Set-Service -Name "\"My Windows Service Name\"" -StartupType Automatic; \
    Set-ItemProperty "\"Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\My Windows Service Name\"" -Name AllowRemoteConnection -Value 1

ENTRYPOINT ["powershell"]
CMD Start-Service \""My Windows Service Name\""; \
    Get-EventLog -LogName System -After (Get-Date).AddHours(-1) | Format-List ;\
    $idx = (get-eventlog -LogName System -Newest 1).Index; \
    while ($true) \
    {; \
      start-sleep -Seconds 1; \
      $idx2  = (Get-EventLog -LogName System -newest 1).index; \
      get-eventlog -logname system -newest ($idx2 - $idx) |  sort index | Format-List; \
      $idx = $idx2; \
    }