Docker 在 Windows 上将网络驱动器添加为卷 [英] Docker add network drive as volume on windows

查看:44
本文介绍了Docker 在 Windows 上将网络驱动器添加为卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网络驱动器安装为卷.这是我正在尝试的命令

I am trying to mount a network drive as a volume. This is the command I am trying

docker run -v //NetworkDirectory/Folder:/data alpine ls /data

我在 Windows 上运行此命令,数据目录变为空.如何将此网络目录作为卷挂载到 Windows 主机上并在容器内访问它?

I am running this command on windows and the data directory is coming up empty. How can I mount this network directory as a volume on the windows host and access it inside the container?

使用本地目录工作正常,因此以下命令按预期工作.

Working with local directories works just fine, so the following command works as expected.

docker run -v c:/Users/:/data alpine ls /data

我可以让它在 linux 中工作,因为我可以使用 cifs-utils 在本地目录上安装共享并将该目录用作卷.

I can make it work in linux since I can mount the share with cifs-utils on a local directory and use that directory as the volume.

看起来这是不可能的:如何在 Docker for Windows (Windows 10) 中挂载网络卷

推荐答案

我的同事想出了这个,它与我们公司的网络驱动器配合使用,它可能会帮助那里的人.

My colleague came up with this and it works with our company network drive and it might help someone out there.

我们首先创建一个名为 mydockervolume 的 docker 卷.

We start by creating a docker volume named mydockervolume.

docker volume create --driver local --opt type=cifs --opt device=//networkdrive-ip/Folder --opt o=user=yourusername,domain=yourdomain,password=yourpassword mydockervolume

  • --driver 指定卷驱动名称
  • --opt 设置驱动程序特定选项.我猜他们在容器启动时被赋予了 linux mount 命令.
    • --driver specifies the volume driver name
    • --opt Sets driver specific options. I guess they are given to the linux mount command when the container starts up.
    • 然后我们可以测试该卷是否适用
      docker run -v mydockervolume:/data alpine ls/data

      We can then test that the volume works with
      docker run -v mydockervolume:/data alpine ls /data

      您可以在此处阅读有关驱动程序特定选项和 docker volume create 的更多信息

      这篇关于Docker 在 Windows 上将网络驱动器添加为卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆