在docker环境中设置IPFS群集

时间:2018-09-27 04:53:58

标签: docker ipfs

我正在尝试使用docker设置一个2节点私有IPFS集群。为此,我使用了ipfs/ipfs-cluster:latest图片。

我的docker-compose文件看起来像:

version: '3'
services:
  peer-1:
    image: ipfs/ipfs-cluster:latest
    ports:
      - 8080:8080
      - 4001:4001
      - 5001:5001
    volumes:
      - ./cluster/peer1/config:/data/ipfs-cluster
  peer-2:
    image: ipfs/ipfs-cluster:latest
    ports:
      - 8081:8080
      - 4002:4001
      - 5002:5001
    volumes:
      - ./cluster/peer2/config:/data/ipfs-cluster

启动容器时出现以下错误

ERROR   ipfshttp: error posting to IPFS: Post http://127.0.0.1:5001/api/v0/repo/stat?size-only=true: dial tcp 127.0.0.1:5001: connect: connection refused ipfshttp.go:745

enter image description here 请帮助解决该问题。

是否存在有关如何在Docker上设置IPFS群集的适当文档。 This文档缺少很多细节。

谢谢。

3 个答案:

答案 0 :(得分:1)

我弄清楚了如何在docker环境中运行多节点IPFS集群。 当前的ipfs/ipfs-cluster(版本为0.4.17)未运行ipfs对等体,即其中的ipfs/go-ipfs。我们需要单独运行它。

因此,现在为了在docker环境中运行多节点(在这种情况下为2个节点)IPSF集群,我们需要运行2个IPFS对等容器和2个与每个对等体相对应的IPFS集群容器1。

因此您的docker-compose文件将如下所示:

version: '3'

networks:
  vpcbr:
    driver: bridge
    ipam:
     config:
       - subnet: 10.5.0.0/16

services:
  ipfs0:
    container_name: ipfs0
    image: ipfs/go-ipfs
    ports:
          - "4001:4001"
          - "5001:5001"
          - "8081:8080"
    volumes:
      - ./var/ipfs0-docker-data:/data/ipfs/
      - ./var/ipfs0-docker-staging:/export
    networks:
      vpcbr:
        ipv4_address: 10.5.0.5

  ipfs1:
    container_name: ipfs1
    image: ipfs/go-ipfs
    ports:
          - "4101:4001"
          - "5101:5001"
          - "8181:8080"
    volumes:
      - ./var/ipfs1-docker-data:/data/ipfs/
      - ./var/ipfs1-docker-staging:/export
    networks:
      vpcbr:
        ipv4_address: 10.5.0.7

  ipfs-cluster0:
    container_name: ipfs-cluster0
    image: ipfs/ipfs-cluster
    depends_on:
      - ipfs0
    environment:
      CLUSTER_SECRET: 1aebe6d1ff52d96241e00d1abbd1be0743e3ccd0e3f8a05e3c8dd2bbbddb7b93
      IPFS_API: /ip4/10.5.0.5/tcp/5001
    ports:
          - "9094:9094"
          - "9095:9095"
          - "9096:9096"
    volumes:
      - ./var/ipfs-cluster0:/data/ipfs-cluster/
    networks:
      vpcbr:
        ipv4_address: 10.5.0.6

  ipfs-cluster1:
    container_name: ipfs-cluster1
    image: ipfs/ipfs-cluster
    depends_on:
      - ipfs1
      - ipfs-cluster0
    environment:
      CLUSTER_SECRET: 1aebe6d1ff52d96241e00d1abbd1be0743e3ccd0e3f8a05e3c8dd2bbbddb7b93
      IPFS_API: /ip4/10.5.0.7/tcp/5001
    ports:
          - "9194:9094"
          - "9195:9095"
          - "9196:9096"
    volumes:
      - ./var/ipfs-cluster1:/data/ipfs-cluster/
    networks:
      vpcbr:
        ipv4_address: 10.5.0.8

这将旋转2个对等IPFS集群,我们可以使用任何一个对等存储和检索文件。

这里的要点是我们需要将IPFS_API提供给ipfs-cluster作为环境变量,以便ipfs-cluster知道其对应的对等方。对于这两个ipfs集群,我们需要具有相同的CLUSTER_SECRET。

答案 1 :(得分:0)

根据您发布的文章:

  

该容器未运行go-ipfs。您应该运行IPFS守护程序   例如,分别使用ipfs / go-ipfs Docker容器。我们   建议安装/ data / ipfs-cluster文件夹以提供自定义,   工作配置以及集群数据的持久性。   通常通过传递-v来实现   :/ data / ipfs-cluster到docker run)。

如果实际上您需要连接到docker-compose内的另一个服务,则可以简单地用服务名称来引用它,因为主机名条目是在docker-compose的所有容器中创建的,因此服务可以与每个容器通信用其他名称代替ip

另外:

  

除非使用--net = host运行docker,否则需要设置$ IPFS_API   或确保配置具有正确的node_multiaddress。

docker-compose中--net = host的等效项为network_mode: "host"(与端口映射不兼容)https://docs.docker.com/compose/compose-file/#network_mode

答案 2 :(得分:0)

@Subhankar我在尝试部署docker-compose时遇到错误:

"The network node_vpcbr cannot be used with services. Only networks scoped to the swarm can be used, such as those created with the overlay driver."

您没有遇到该错误?

相关问题