问题描述
我正在尝试将网络驱动器安装为卷.这是我正在尝试的命令
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
设置驱动程序特定选项.我猜他们在容器启动时被赋予了 linuxmount
命令.--driver
specifies the volume driver name--opt
Sets driver specific options. I guess they are given to the linuxmount
command when the container starts up.
然后我们可以测试该卷是否适用docker run -v mydockervolume:/data alpine ls/data
We can then test that the volume works withdocker run -v mydockervolume:/data alpine ls /data
您可以在此处阅读有关驱动程序特定选项和 docker volume create 的更多信息
这篇关于Docker 在 Windows 上将网络驱动器添加为卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!