简体   繁体   English

docker swarm和命名卷出现问题

[英]Issue with docker swarm and named volumes

I'm having some issues using named volumes in one of my docker stacks. 我在我的一个Docker堆栈中使用命名卷时遇到一些问题。

Basically I'm running a bitcoin node developed by bcoin. 基本上,我正在运行由bcoin开发的比特币节点。 What I'm trying to achieve is to have the containers running the nodes to write and read the blockchain data from a Digital Ocean volume attached to one of my droplets (VMs). 我要实现的目标是让运行节点的容器从附着到我的一个液滴(VM)上的Digital Ocean卷中写入和读取区块链数据。 I'm guessing I'm having some issues because I normally use volumes one way only, having stuff in my host machine being present in my containers. 我猜我遇到了一些问题,因为我通常仅以一种方式使用卷,因为主机中的内容存在于容器中。

This DO volume is present in the directory /mnt/blockchain-data in my manager node (or droplet). 该DO卷存在于我的管理器节点(或Droplet)中的目录/mnt/blockchain-data中。

So here's my docker-stack.yml file: 所以这是我的docker-stack.yml文件:

version: "3.6"
services:
  bcoin:
    image: hollarves/bcoin-mueve
    ports:
      #-- Mainnet
      # - "8333:8333"
      # - "8332:8332" # RPC/HTTP
      # - "8334:8334" # Wallet
      #-- Testnet
      - "18333:18333"
      - "18332:18332" # RPC/HTTP
      - "18334:18334"
    networks:
      - bitcoin-private-net
    volumes:
      - blockchain:/data
      - ${PWD}/bitcoin/secrets/bcoin.conf:/data/bcoin.conf
      - ${PWD}/bitcoin/secrets/wallet.conf:/data/wallet.conf
    environment:
      BCOIN_CONFIG: /data/bcoin.conf
    deploy:
      labels:
        - "traefik.docker.network=bitcoin-net"
        - "traefik.bcoin.frontend.rule=Host:bcoin.xxxx.com"
        - "traefik.bcoin.backend=bcoin"
        - "traefik.bcoin.port=18332"
        - "traefik.bcoin.frontend.entryPoints=http"
        - "traefik.bcoin-wallet.frontend.rule=Host:bcoin-wallet.xxxx.com"
        - "traefik.bcoin-wallet.backend=bcoin-wallet"
        - "traefik.bcoin-wallet.port=18334"
        - "traefik.bcoin-wallet.frontend.entryPoints=http"
      placement:
        constraints:
          - node.role == manager

volumes:
  blockchain:
    driver: local
    driver_opts:
      type: bind
      device: :/mnt/blockchain-data

networks:
  bitcoin-private-net:
    external: true

So basically I want whatever is in the /data directory of my containers to be synced with whatever it is in my /mnt/blockchain-data in my host machine. 因此,基本上,我希望将容器的/data目录中的内容与主机中/mnt/blockchain-data中的内容进行同步。 If the container writes some new blocks they should be copied to the /mnt/blockchain-data dir, and if a new bitcoin node is replicated, it should already have it's data directory synced with the files in my host machine. 如果容器写入了一些新块,则应将其复制到/mnt/blockchain-data目录中,并且如果复制了新的比特币节点,则其数据目录应该已经与主机中的文件同步。

The main idea is to avoid redownloading the blockchain whenever a node is destroyed and recreated for whatever reason. 主要思想是避免由于任何原因破坏和重新创建节点时重新下载区块链。 As well as being able to replicate as many nodes I want without having to download the blockchain for each one of them. 不仅能够复制所需的节点,而且不必为每个节点下载区块链。

Any ideas on what I might be doing wrong? 关于我可能做错了什么的任何想法? Thanks! 谢谢!

There are various ways to achieve your goal, especially in a swarm environnement. 有多种方法可以实现您的目标,尤其是在蜂拥的环境中。 At first, let's say that docker does not sync volumes among swarm, unless you use a suited driver. 首先,假设docker不会在群集之间同步卷,除非您使用合适的驱动程序。 Thus, you'll have to use drivers or other solutions, according to whether you need r/w or only read! 因此,根据您需要读/写还是只读,您必须使用驱动程序或其他解决方案!

Here are a few ideas (not all solutions!) : 这里有一些想法(不是所有的解决方案!):

  • You may mount share drive among the machines hosting your nodes, by exemple NFS . 您可以通过示例NFS在承载节点的计算机之间安装共享驱动器。 Ensure they are mounted on the same path on all hosts. 确保将它们安装在所有主机上的相同路径上。 Then, just bind mound the path to you container /data. 然后,只需将路径绑定到容器/ data。 Though, this is not the easiest way. 虽然,这不是最简单的方法。 But if you need R/W options, this is a suited solution. 但是,如果需要R / W选项,这是一个合适的解决方案。 However, note that this solution can be seen as introducing a SPOOF , which is not that great in production environnement. 但是,请注意,该解决方案可以看作是引入了SPOOF ,这在生产环境中并不是那么好。
  • you may use named volume as well, but in a distributed environment, you will have to use a volume driver to be able to sync them. 您也可以使用命名卷,但是在分布式环境中,必须使用卷驱动程序才能同步它们。 Docker doc has a few exemples . Docker文档有一些示例 You have a list of volume plugings here . 您可以在此处找到音量插头列表。 According to which one you choose, you may eliminate the SPOOF problem. 根据您选择的一种,可以消除SPOOF问题。
  • Eventually, if you don't need r/w possibilities, swarm mode allow you to use secrets / configs . 最终,如果您不需要读写的可能性,则可以使用群模式来使用secrets / configs Especially, secrets are obviously suited to such sensitive data as yours. 特别是, 秘密显然适合您这样的敏感数据。

Hope this helps! 希望这可以帮助!

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

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