Setting up 2 peer IPFS cluster on docker

I am trying to set up a 2 node IPFS on docker. My docker-compose file looks as follows
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
This gives following ERROR on starting.

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

Whats going wrong with this?
Is there any documentation or tutorial about how to setup IPSF cluster on docker, step by step. Although this tells about deploying IPFS using docker, its misses on lot.

Hello,

yes, we are missing more detailed documentation about deploying with docker, particularly providing compose templates.

The existing docs do however point out that you need to run ipfs on the side. The error you are getting is related. Also, the ports you are defining are ipfs ports, not cluster. Cluster uses 9094, 9095 and 9096 by default (https://cluster.ipfs.io/documentation/security/).

Also I cannot see it, but just in case: for your docker cluster to start correctly (with the given compose file) you will need the configuration files correctly set so that the cluster can start with a fixed peerset for the first time: https://cluster.ipfs.io/documentation/starting/#starting-multiple-peers-with-a-fixed-peerset . Otherwise, maybe the peers may run but maybe as two separate clusters of 1 peer.

Finally, there is a typo in your peer-2 image: ipfs/ipfs-cluster:latests should be latest.

We would be happy if you share your results, maybe we can use it to document the process for someone else.

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.

1 Like

This is great @subhankar.

You should be able to provide IPFS_API as /dns4/ipfs0/tcp/5001 (I think docker will let ipfs0 resolve to whatever IP was assigned to that container right?). In that case, you should not need to fix the IP addresses of the ipfs containers. I haven’t tested this with docker so it would be very cool if you can tell me if it works as expected. You can also so the same with the cluster addresses in the peerstore file: dns4/ipfs-cluster1/tcp/9094/ipfs/peerid.

Ok, I wrote a working docker-compose.yml