Setting up 2 peer IPFS cluster on docker

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