How can I run a program inside windows container using a local account, not-ContainerAdministrator

Hi,

I am trying to install a program on my docker image based on windowsservercore.
This application should be installed under a local account which I have created giving it the instruction in docker file:

FROM microsoft/windowsservercore
RUN “net user /add custom-admin Control01”
RUN “net localgroup Administrators custom-admin /add”

Once a container is launched, I start a new cmd session to run a *.bat, but the issue is that it should be installed by custom-admin local account instead of user manager/ContainerAdministrator

c:\>runas /user:custom-admin SilentInstall_Server.bat
Enter the password for custom-admin:
Attempting to start SilentInstall_Server.bat as user “0E81A78A0926\custom-admin” …

c:\>whoami
user manager\containeradministrator

c:\>

FROM microsoft/windowsservercore
RUN net user /add custom-admin
RUN net localgroup Administrators custom-admin /add
USER custom-admin
RUN SilentInstall_Server.bat

Unfortunately, it doesn’t work right now:

Dockerfile:

FROM mcr.microsoft.com/windows/servercore:20H2

RUN net user mqAdmin "mqmP@ss" /ADD
RUN net localgroup Administrators /add mqAdmin

USER mqAdmin
RUN whoami

Result:

container 077b90464f938f0358e98f4b16838e9ec8ff0bf0866c1f8fb711ab6f28978b7e encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The user name or password is incorrect

Sorry, it is my mistake:
it is important to local user doesn’t have password:

RUN net user mqAdmin /ADD

In this case, it is possible to execute command with docker exec.

1 Like