How to map network shared location to docker for windows

Hi,

I am running docker for windows on Windows 10

I would like attach a volume to a linux based container. This volume in available on our intranet and is a SMB storage.

On my host machine, I have mapped it with letter G:.

$user = “publishingstudio@xxxxxx”
$pwd = ConvertTo-SecureString “xxxxxxxxxx” -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user,pwd) New-SmbGlobalMapping -RemotePath \\xxxxx\publishingstudio -Credential $cred -LocalPath G:

I am able to access its content using windows explorer

Now, I have tried to shared this location with windows for docker using docker for windows setting panel/

When I click on ‘Apply & Restart’, I have a strange behaviour. A line is added but is empty.

I then try to use it using a docker run command.

docker run -v g:/:/data my_container

The container is launch but there is no data.

What is wrong?

Thanks for you help.

I would try to mount it directly into the container with mount -t cifs.

It means I need to launch the container with a --priviledge option because I saw that mount command is not available in “docker run” normal mode.

Do you have an example of how to use mount with credantials? I am not so familiar with linux environment.

Thanks for you help.

Just a minimalistic example in a compose file:

---
version: "3.7"

services:
  movies:
    image: debian
    command: ['ls', '/movies']
    volumes:
      - mymovies:/movies

volumes:
  mymovies:
    driver_opts:
      type: cifs
      o: "username=${SMBUSER},password=${SMBPASSWORD}"
      device: "//192.168.1.220/Media 2/Videos"

I have a NAS with movies at the address you see above. To run the compose file enter:

$ export SMBUSER= # your smb user name here
$ export SMBPASSWORD= # and here your password
$ docker-compose up

It will just list the files in Videos and then the container exits.
You will probably have to set some more options like iocharset to get a working system. Take a look at man mount.cifs for that.

(Edit: I forgot to mention that I typed these commands in WSL2. In PowerShell you set environment variables with $Env:....)

Thanks for you help

version: "3.8"

services:
  app:
image: debian
command: ['ls', '/shared']
volumes:
  - networkShared:/shared

volumes:
  networkShared:
driver_opts:
  type: cifs
  o: "username=publishingstudio@stro.fr.traceparts.com,password=xxxx"
  device: "//syno3.stro.fr.traceparts.com/publishingstudio$"

I get the following error
ERROR: Invalid interpolation format for “driver_opts” option in volume “networkShared”: “//syno3.stro.fr.traceparts.com/publishingstudio$

Is it due to the ‘$’ character?

Ok I found the problem I need to unspecify $ by doubling it.

Now I get another error :

Where does /var/lib/docker/volumes/test_networkShared/_data comes from?

This error looks the same most of the time and .../_data is the place where the volume was created. List your volumes with docker volume ls, delete the one that was created and try again. Maybe you should use variables as in my example.

Thanks for this help! Thanks for sharing this important information!