如何将多个容器中的写入同步到群集上的同一卷? [英] How to synchronise writes from multiple containers to the same volume on a swarm?
问题描述
使用 flock 在Docker群中?
Is it safe / possible to use flock in a docker swarm?
我正在寻找一种安全的方法,以使多个容器写入同一文件(在同一卷上).我知道,泊坞窗将在单个主机上绑定安装.我不确定的是当通过docker-compose在集群上旋转容器时,这是如何工作的.
I'm looking for a safe way for multiple containers to write to the same file (on the same volume). I know that on a single host docker will bind mount. What I'm not certain about is how this works when spinning up containers via docker-compose on a swarm.
如果服务中有多个同一图像的实例,并且它们全部共享一个卷,那么当我在一个群集中启动该容器时,这些容器将在单独的主机上启动吗?如果是这样,将如何在操作系统级别共享该卷?我有什么同步选项来控制并发写入?
If I have multiple instances of the same image in a service and these all share a volume then when I start this on a swarm will the containers be started on separate hosts? If so how will the the volume be shared at an OS level? What synchronisation options do I have for controlling concurrent writes?
推荐答案
创建NFS卷
示例:
# create a reusable volume
$ docker volume create --driver local \
--opt type=nfs \
--opt o=nfsvers=4,addr=192.168.1.1,rw \
--opt device=:/path/to/dir \
foo
# inside a docker-compose file
...
volumes:
nfs-data:
driver: local
driver_opts:
type: nfs
o: nfsvers=4,addr=192.168.1.1,rw
device: ":/path/to/dir"
这篇关于如何将多个容器中的写入同步到群集上的同一卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!