Remote container mount network share from Windows host

Viewed 1736

Problem Description

I would like to specify a mount to a network share from the devcontainer.json "mounts" property so that I can write scripts that pull files from that network share and can run on multiple host machines.

I can see that VSCode Remote Containers is purely passing through the "mounts" property value to the docker run --mount parameter. So if I can find a way to get that to work, then I should be set.

I can mount a network share from a WSL2 distribution with sudo mount -t drvfs //myserver/projects /mnt/p and mount it in a container with docker run --rm -it --mount source=/mnt/p,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash and I can list that directory in the container to get the contents of the network share. But that only works when I execute the docker commands from within the WSL2 distribution terminal window. For this to work from VSCode remote containers, I need this to work from the Windows host machine. And I have yet to find any equivalent commands that work from the standard Windows Command Prompt.

What I've tried

These were all attempted from the Windows command prompt on the host machine.
And I have a mapped network drive from P: to \\myserver\projects.

# Even with the mount to the network share still present in the primary WSL distribution
docker run --rm -it --mount source=/mnt/p,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /mnt/p
docker run --rm -it --mount source=\\myserver\projects,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: \\myserver\projects%!(EXTRA string=is not a valid Windows path).
docker run --rm -it --mount source=//myserver/projects,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /myserver/projects.
docker run --rm -it --mount source=P:\,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
ls /mnt/p
# Empty directory
docker volume create --opt type=cifs --opt device=//myserver/projects projects
docker run --rm -it --mount source=projects,target=/mnt/p,type=volume,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: error while mounting volume '/var/lib/docker/volumes/projects/_data': failed to mount local volume: mount //myserver/projects:/var/lib/docker/volumes/projects/_data: invalid argument.
docker volume create --opt type=cifs --opt device=P:\ projects
docker: Error response from daemon: error while mounting volume '/var/lib/docker/volumes/projects/_data': failed to mount local volume: mount P:\:/var/lib/docker/volumes/projects/_data: invalid argument.
New-SmbGlobalMapping -RemotePath \\myserver\projects -LocalPath R:
docker run --rm -it --mount source=R:\,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /run/desktop/mnt/host/uC/myserver/projects.
New-SmbGlobalMapping -RemotePath \\myserver\projects -LocalPath R:
docker run --rm -it --mount source=R:\,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /run/desktop/mnt/host/uC/myserver/projects.

And I've tried all combinations of \ vs / with similar errors

0 Answers
Related