Search code examples
dockerdockerfiledocker-for-windowswindows-containerwindows-share

Using local accounts in windows docker container to access machines on the same network


I have a Windows machine, machine 1 on a network with a local account called testlocal.

I have another machine, machine 2 on the network with the same local account, testlocal.

From my machine 1, I am able to access a folder with share enabled to testlocal because I have the same testlocal username and password on both machines as local accounts.

Now, when i build a docker container on machine 1. I see that I can ping machine 2. I can even call:

net use \\machine2 <password> /USER:machine2\testlocal

And gain access to the shared drive.

But, when I do the following in my dockerfile on machine1:

RUN net user testlocal <password> /ADD /EXPIRES:NEVER
RUN net LOCALGROUP Administrators /ADD testlocal

And then cmd into the container on machine1 to test, it says the password is incorrect when running:

net view \\machine2 /USER:testlocal

After the above command fails it prompts for a password, I then enter the password (the exact same password that i specify in my dockerfile) and it works.

My goal is to have an entry point in my container that allows user to enter the credentials for the common local account, and then let the application running in the container to access those shared drives without a username and password.

What is the proper way to gain access to windows shares? Is this approach reasonable?


Solution

  • Ended up ensuring the application running would set up the network shares on initialization. Must perform a system call:

    NET use \\\\<sharePath> <password> /USER:<user> /PERSISTENT:YES"
    

    This seems to work.