Docker在Windows上将网络驱动器添加为卷

Docker在Windows上将网络驱动器添加为卷

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

问题描述

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

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

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



使用本地目录可以很好地工作,因此以下命令可以正常工作

  docker run -vc:/ Users /:/ data alpine ls / data 

我可以使其在Linux中工作,因为我可以将cifs-utils共享安装在本地目录上,并将该目录用作卷。 / p>

编辑:看起来这是不可能的:

解决方案

我的同事想出了这个方法,它可以与我们公司的网络驱动器一起使用,并且可能会帮助那里的某个人。



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

  docker volume create --driver lo cal --opt type = cifs --opt device = // networkdrive-ip / Folder --opt o = user =您的用户名,domain =您的域,password =您的密码mydockervolume 




  • -驱动程序指定卷驱动程序名称

  • -opt 设置驱动程序特定的选项。我猜想它们在容器启动时被赋予了Linux mount 命令。



然后我们可以测试该卷是否与

docker run -v mydockervolume:/ data alpine ls / data




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

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

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.

Edit: Looks like this is not possible: How to mount network Volume in 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.

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 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.

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

Here you can read more about driver specific options and docker volume create

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

08-01 01:35