7

I am trying to set up a 2 node private IPFS cluster using docker. For that purpose I am using ipfs/ipfs-cluster:latest image.

My docker-compose file looks like :

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

While starting the containers getting following error

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 Please help with the problem.

Is there any proper documentation about how to setup a IPFS cluster on docker. This document misses on lot of details.

Thank you.

Subhankar
  • 692
  • 7
  • 25

2 Answers2

4

I figured out how to run a multi-node IPFS cluster on docker environment. The current ipfs/ipfs-cluster which is version 0.4.17 doesn't run ipfs peer i.e. ipfs/go-ipfs in it. We need to run it separately.

So now in order to run a multi-node (2 node in this case) IPSF cluster in docker environment we need to run 2 IPFS peer container and 2 IPFS cluster container 1 corresponding to each peer.

So your docker-compose file will look as follows :

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

This will spin 2 peer IPFS cluster and we can store and retrieve file using any of the peer.

The catch here is we need to provide the IPFS_API to ipfs-cluster as environment variable so that the ipfs-cluster knows its corresponding peer. And for both the ipfs-cluster we need to have the same CLUSTER_SECRET.

Subhankar
  • 692
  • 7
  • 25
0

According to the article you posted:

The container does not run go-ipfs. You should run the IPFS daemon separetly, for example, using the ipfs/go-ipfs Docker container. We recommend mounting the /data/ipfs-cluster folder to provide a custom, working configuration, as well as persistency for the cluster data. This is usually achieved by passing -v :/data/ipfs-cluster to docker run).

If in fact you need to connect to another service within the docker-compose, you can simply refer to it by the service name, since hostname entries are created in all the containers in the docker-compose so services can talk to each other by name instead of ip

Additionally:

Unless you run docker with --net=host, you will need to set $IPFS_API or make sure the configuration has the correct node_multiaddress.

The equivalent of --net=host in docker-compose is network_mode: "host" (incompatible with port-mapping) https://docs.docker.com/compose/compose-file/#network_mode

yosefrow
  • 2,128
  • 20
  • 29
  • Is there any tutorial or example on how to set up a IPFS cluster using docker. About running go-ipfs docker separately, if we run it separately, then how do we connect the go-ipfs with the ipfs-cluster – Subhankar Sep 27 '18 at 06:08