SturmUndDrang
SturmUndDrang

Reputation: 1956

Install Windows service in Docker container

When I try to install an app as a service in my dockerfile I get an error that indicates that installutil.exe is showing the username dialog when installing the service. Initially I wanted to use an account on the host's domain, but it seems Docker for Windows doesn't support the host network setting that is available on linux.

To get around this I am creating an admin user first and then calling installutil with the username and password parameters. This gives the error

The account name is invalid or does not exist, or the password is invalid for the account name specified.

FROM microsoft/dotnet-framework
SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]

RUN New-LocalUser -Name "testuser" -Password (ConvertTo-SecureString -AsPlainText "Stackoverflow1234!" -Force) -FullName "Test.User" -Description "LocalAdministrator"
RUN Add-LocalGroupMember -Group administrators -Member  adapteruser -Verbose

RUN New-Item -Path "C:/dev" -ItemType directory

WORKDIR /dev

COPY ".\dev" "C:\dev"

RUN "C:/Windows/Microsoft.NET/Framework64/v4.0.30319/InstallUtil.exe" /username=testuser /password=Stackoverflow1234! /LogToConsole=true /ShowCallStack myapp.exe

I've also tried:

RUN net user /add testuser Stackoverflow1234!
RUN net localgroup administrators testuser /add
RUN net user

I have reviewed this similar question already: Dockerizing a Windows Service Docker for Windows

Upvotes: 3

Views: 10182

Answers (1)

SturmUndDrang
SturmUndDrang

Reputation: 1956

To use the new user I had to add ".\" to the username (for local machine):

RUN "C:/Windows/Microsoft.NET/Framework64/v4.0.30319/InstallUtil.exe" /username=.\testuser /password=Stackoverflow1234! /LogToConsole=true /ShowCallStack myapp.exe

Upvotes: 0

Related Questions