New-SmbGlobalMapping samba share for docker is not mounted after host reboot


  • Hi,

    How can I persist the

    $creds = Get-Credential 
    New-SmbGlobalMapping -RemotePath \\contosofileserver\share1 -Credential $creds -LocalPath G:

    commands i used to mount a share for the docker containters?
    After every reboot the share is no longer available.
    Apparently no "persistent" parameter is present in the powershell commandlet.

    Thank you

    Friday, May 18, 2018 3:52 PM

All replies

  • Hi,

    "When using SMB global mapping for containers, all users on the container host can access the remote share. Any application running on the container host will also have access to the mapped remote share."

    And it needs to use the credentials to authenticate with the remote SMB server.  In general when a computer restarts, the cache will usually clear, so that you loose, and may need to recreate again.

    In the blog, The commands, "$creds = Get-Credentials" means this command gets a credential object and saves it in the $Creds variable.

    Maybe you could choose to use the specific user name and password, not try the Credentials so that after reboot it could directly to  authenticate  the user and the password.

    There's another forum post about this issue below:

    Kind regards,

    Blog:  LinkedIn:   

    Friday, May 18, 2018 6:35 PM
  • I can use a specific username and password, but how/where do I save the credentials and how do I make the share persistent after reboots?
    Tuesday, May 22, 2018 10:37 AM
  • In the blog mentioned above they use the following command to do the mapping:

    $creds = Get-Credentials
    New-SmbGlobalMapping -RemotePath \\contosofileserver\share1 -Credential $creds -LocalPath G:

    And instead of using the $creds variable you would put a username and password.

    Kind regards,

    Blog:  LinkedIn:   

    Tuesday, May 22, 2018 12:41 PM
  • Thank you, I could read your previous answer as I could read the same answer copypasted in the other thread you linked, but it adds nothing to the topic. Stop copypasting the same answer just to get points please, i get that I have to use hard-coded user and password instead of getting them from the user.

    As you don't seem to know how to do what you said yourself, I created a powershell script so that username and password can be statically read from somewhere other than the user input.

    $user = "domain\username"
    $passFile = "c:\file_with_secured_password.txt"
    $pass = Get-Content $passFile | ConvertTo-SecureString
    $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
    New-SmbGlobalMapping -RemotePath \\host\share -Credential $creds -LocalPath E:

    this works if you manually run the script, but the share is not restored after a reboot unless you run the script again. Having the script run in a scheduled task does not ensure that the share will be mounted before any service starts, so it is worth nothing.

    Anybody has any idea how to make it persistent across reboots?

    Wednesday, May 23, 2018 8:18 AM
  • As far as I know the only way would be to create a task schedule like you mentioned.

    The service you are talking about, could it be changed to delayed start so that the samba share could have time to be mounted before the service runs? Or then maybe create a dependency for the service.

    Kind regards,

    Blog:  LinkedIn:   

    Wednesday, May 23, 2018 8:35 AM
  • Thank you,

    the service is the docker engine. I can probably set it as delayed but it won't ensure that a slow-mounting share will start before. I could probably do this:

    1. remove the docker service from autostart
    2. use a windows service wrapper to run a powershell script
    3. put the mount command at the beginning of the script
    4. put the docker start command line at the end of the script
    5. set the wrapped script service as autostart

    Wednesday, May 23, 2018 9:42 AM
  • The solution you provided sounds like it could work indeed, tell us how it goes!

    Kind regards,

    Blog:  LinkedIn:   

    Wednesday, May 23, 2018 2:28 PM