简体   繁体   English

Docker swarm 带卷装容器

[英]Docker swarm with volume mounted container

I have a docker container, which has its volume mounted with host volume.我有一个 docker 容器,它的卷与主机卷一起安装。 Here is its docker-compose service:这是它的 docker-compose 服务:

  core:
    image: index.docker.io/kaushal/demo_img
    volumes:
      - ./data/custom:/opt/custom:z

Here ./data/custom is host directory and it's mounted with /opt/custom dir in container.这里./data/custom是主机目录,它与容器中的/opt/custom目录一起挂载。 Now, to achieve high availability, I want to run multiple replicas of this container using docker swarm on different nodes.现在,为了实现高可用性,我想在不同的节点上使用 docker swarm 运行这个容器的多个副本。

When I start swarm, it always shows 0/2 replicas.当我启动 swarm 时,它总是显示0/2副本。 The reason is highlighted here: https://stackoverflow.com/a/56707801/5353128 (tl;dr because I don't have ./data/custom dir in other swarm node).原因在这里突出显示: https://stackoverflow.com/a/56707801/5353128 (tl;博士,因为我在其他 swarm 节点中没有./data/custom目录)。

This problem seems to be the common problem with docker swarm but I couldn't find the straightforward solution for this.这个问题似乎是 docker swarm 的常见问题,但我找不到直接的解决方案。 Some of the SO posts suggests to use shared volumes but it's not clear how to implement such shared volume for such a simple usecase.一些 SO 帖子建议使用共享卷,但不清楚如何为这样一个简单的用例实现这样的共享卷。

Also, is there any alternative to shared volumes?此外,是否有任何替代共享卷? Any reference would be appreciated.任何参考将不胜感激。 Thanks!谢谢!

Docker itself only mounts things for a volume. Docker 本身只为一个卷安装东西。 It itself does not have any sort of file sharing mechanism built in. The type of volume that you have specified is a bind mount, which just mounts a directory on the host where the container is running to a location inside that container.它本身没有内置任何类型的文件共享机制。您指定的卷类型是绑定挂载,它只是将运行容器的主机上的目录挂载到该容器内的某个位置。 See https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount for info on what a bind mount is in the generic linux/unix sense and https://docs.docker.com/storage/bind-mounts/ for the docker-specific variety. See https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount for info on what a bind mount is in the generic linux/unix sense and https://docs.docker.com/ storage/bind-mounts/用于特定于 docker 的品种。

Another type of mount is NFS.另一种类型的挂载是 NFS。 https://stackoverflow.com/a/44825756/4930423 is an answer that discusses that fairly well. https://stackoverflow.com/a/44825756/4930423是一个很好地讨论了这个问题的答案。

You could also introduce other filesystem types as well-- cifs/samba is another possibility.您也可以引入其他文件系统类型——cifs/samba 是另一种可能性。

Another approach that folks use is to make each node mount one nfs/cifs/other type shared directory using the host's /etc/fstab, and then from there use a docker bind mount.人们使用的另一种方法是让每个节点使用主机的 /etc/fstab 挂载一个 nfs/cifs/other 类型的共享目录,然后从那里使用 docker 绑定挂载。 Any file sharing technology that meets the requirements for your workload will work with this setup-- make sure your io is high enough and that the workload in question doesn't have any fundamental problems with the inevitable increased latency with a remote access type filesystem.任何满足您的工作负载要求的文件共享技术都可以使用此设置 - 确保您的 io 足够高,并且所讨论的工作负载没有任何基本问题,因为远程访问类型文件系统不可避免地会增加延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM