来自 Windows 主机的远程容器挂载网络共享

Tyl*_*sen 5 visual-studio-code windows-subsystem-for-linux docker-for-windows vscode-remote

问题描述

我想从 devcontainer.json“mounts”属性指定一个网络共享的挂载,以便我可以编写从该网络共享中提取文件的脚本,并可以在多台主机上运行。

我可以看到 VSCode 远程容器纯粹是将“mounts”属性值传递给docker run --mount参数。所以,如果我能找到一种方法让它发挥作用,那么我应该做好准备。

我可以从 WSL2 发行版挂载网络共享sudo mount -t drvfs //myserver/projects /mnt/p并将其挂载在容器中docker run --rm -it --mount source=/mnt/p,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash,我可以在容器中列出该目录以获取网络共享的内容。但这仅在我从 WSL2 分发终端窗口中执行 docker 命令时才有效。为了在 VSCode 远程容器中工作,我需要它在 Windows 主机上工作。而且我还没有找到任何可从标准 Windows 命令提示符运行的等效命令。

我试过的

这些都是从主机上的 Windows 命令提示符尝试的。
我有一个从P:到的映射网络驱动器\\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
Run Code Online (Sandbox Code Playgroud)
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).
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
docker run --rm -it --mount source=P:\,target=/mnt/p,type=bind,readonly=true ubuntu:18.04 bash
ls /mnt/p
# Empty directory
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)

而且我已经尝试了所有具有类似错误的\vs组合/