【问题标题】:Sharing data between two containers in docker swarm在 docker swarm 中的两个容器之间共享数据
【发布时间】:2018-05-08 18:51:43
【问题描述】:

我正在尝试使用 NFS 卷在两个容器之间共享数据。 我在我的 [server/docker manager] var/nfsshare 中设置了一个 nfs 共享驱动器,我的 [client/docker worker] /mnt/nfs/var/nfsshare 也可以使用这个相同的驱动器,并且我能够共享数据。

采取的步骤 将此位置用作我的 docker compose 文件中的卷。 当我使用 docker-compose up 来启动我的容器时,一切正常,我可以共享数据。 但是当我启动 docker swarm 时,我的 [client/worker] 机器中的容器无法访问挂载的卷。

这是我的撰写文件

version: '3.5'

services:

  workerA:
    image: custom1
    tty: true
    deploy:
      replicas: 2
      placement:
        constraints: [node.role == worker]
    volumes:
      - type: volume
        source : test
        target : /data                      
        volume:
            nocopy: true

  serverB:
    image: custom2
    tty: true
    deploy:
      placement:
        constraints: [node.role == manager]
    ports:
      - "7000:7000"
    volumes:
      - type: volume
        source : test
        target : /data
        volume:
            nocopy: true

volumes:
  test
    driver: local
    driver_opts:
      type: "nfs"
      o: addr=192.168.0.100,nolock,soft,rw   # this is the IP of the host for the manager.
      device: ":/var/nfsshare"

我在这里缺少什么?

【问题讨论】:

    标签: docker docker-compose docker-swarm nfs


    【解决方案1】:

    我确实设法找出了问题的原因。只是发布以便将来可以帮助某人。

    客户端机器已经有一个名为 SwarmName_test 的现有卷,并且每当我尝试重新创建该集群时,它没有重新创建该卷,而是使用指向不同路径的旧卷。

    对调试有用的命令 docker 检查 [volumeName/containerName 等] df [列出centOS中的挂载]。

    有用的指南 设置 NFS https://www.howtoforge.com/nfs-server-and-client-on-centos-7 创建撰写文件 https://blog.dahanne.net/2017/11/20/docker-swarm-and-nfs-volumes/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2019-12-26
      • 2017-09-18
      • 1970-01-01
      相关资源
      最近更新 更多