创建一个Docker Swarm v1.12.3服务并挂载NFS卷 [英] create a Docker Swarm v1.12.3 service and mount a NFS volume
问题描述
我无法为Docker Swarm挂载NFS卷,并且缺少有关--mount语法的适当官方文档(
I'm unable to get a NFS volume mounted for a Docker Swarm, and the lack of proper official documentation regarding the --mount syntax (https://docs.docker.com/engine/reference/commandline/service_create/) doesnt help.
我基本上已经尝试过使用以下命令行来创建一个简单的nginx服务,其中将/kkk目录安装到NFS卷上:
I have tried basically this command line to create a simple nginx service with a /kkk directory mounted to an NFS volume:
docker服务创建--mount type = volume,src = vol_name,volume-driver = local,dst =/kkk,volume-opt = type = nfs,volume-opt = device = 192.168.1.1:/your/nfs/path --name测试nginx
docker service create --mount type=volume,src=vol_name,volume-driver=local,dst=/kkk,volume-opt=type=nfs,volume-opt=device=192.168.1.1:/your/nfs/path --name test nginx
命令行被Swarm接受并且服务由Swarm调度,但是容器从未达到运行"状态,并且Swarm每隔几秒钟就会尝试启动一个新实例.我将守护程序设置为调试,但有关卷显示没有错误...
The command line is accepted and the service is scheduled by Swarm, but the container never reaches "running" state and swarm tries to start a new instance every few seconds. I set the daemon to debug but no error regarding the volume shows...
使用NFS卷创建服务的正确语法是什么?
Which is the right syntax to create a service with a NFS volume?
非常感谢
推荐答案
我在这里找到了一篇文章,展示了如何安装nfs共享(并且对我有用):
I found an article here that shows how to mount nfs share (and that works for me): http://collabnix.com/docker-1-12-swarm-mode-persistent-storage-using-nfs/
sudo docker service create \
--mount type=volume,volume-opt=o=addr=192.168.x.x,volume-opt=device=:/data/nfs,volume-opt=type=nfs,source=vol_collab,target=/mount \
--replicas 3 --name testnfs \
alpine /bin/sh -c "while true; do echo 'OK'; sleep 2; done"
更新:
如果要与docker-compose一起使用,可以执行以下操作:
Update:
In case you want to use it with docker-compose you can do it the following:
version: '3'
services:
alpine:
image: alpine
volumes:
- vol_collab:/mount
deploy:
mode: replicated
replicas: 2
command: /bin/sh -c "while true; do echo 'OK'; sleep 2; done"
volumes:
vol_collab:
driver: local
driver_opts:
type: nfs
o: addr=192.168.xx.xx
device: ":/data/nfs"
然后使用
docker stack deploy -c docker-compose.yml test
这篇关于创建一个Docker Swarm v1.12.3服务并挂载NFS卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!