Hyperledger Fabric on Multiple Hosts using Docker Swarm and Compose

Mallikarjun Sarvepalli
4 min readJul 21, 2018

--

Introduction

[**update] To deploy Hyperledger Fabric on Kubernetes, refer to my article “ Deploying Hyperledger Fabric on Kubernetes using Helm & Argo (with Fabric-CA instead of cryptogen)

To deploy Hyperledger Fabric v 1.2 on multiple hosts using Docker swarm click here .

Deploying Hyperledger Fabric on multiple hosts involves multiple steps. Using docker Swarm/Kubernetes to connect multiple containers on different hosts is one of the possible options. I followed this post Hyperledger fabric on multiple hosts which uses docker swarm, creates an overlay network to connect docker containers on multiple hosts. This is an excellent post which explains the concepts and sets the base (credits to Abdul Wahab). However, lack of docker compose support made me to manually execute lot of commands. So I tried to use Docker swarm with compose, customized byfn (Hyperledger - Build Your First network – from Hyperledger tutorials ) to run on multiple hosts.

Topology

Deploying Hyperledger Fabric on multiple hosts involves multiple steps. Using docker

1. PC-1

  • Orderer (orderer.example.com) -port 7050

2. PC-2

  • CA1 (ca.org1.example.com) -port 7054
  • Org1 Peer0 (peer0.org1.example.com) -port 7051,8051
  • Org1 Peer1 (peer1.org1.example.com) -port 7053,8053

3. PC-3

  • CA2 (ca.org2.example.com) -port 7054
  • Org2 Peer0 (peer0.org2.example.com) -port 7051,8051
  • Org2 Peer1(peer1.org2.example.com) -port 7053,8053

Make sure above specified ports are not blocked with firewall. Open 2377,7946,4789 ports for docker swarm.

Prerequisites

Follow this link to install all the dependencies on each host.

List of components that I used

  • Ubuntu-16.04
  • Fabric - 1.1.0 (This version is not tested with 1.2.0)
  • Go - 1.9.3
  • Docker -18.03.1-ce
  • Docker-Compose - 1.18.0
  • Node - v8.11.3

Setup

Execute below steps 1-3 on all hosts (PC-1, PC-2 & PC-3)

1) Clone Hyperledger fabric-samples

2) go to fabric-samples directory

3) clone Fabric Multi Network source code from https://github.com/mallikprojects/fabric-multi-network

4) Generate crypo data, docker compose templates and copy to all the hosts

  • ./bymn.sh generate crypto-config.yaml
  • crypto-config — copy to all three hosts
  • channel-artifacts — copy to all three hosts
  • docker-compose-orderer.yaml — copy to PC-1
  • docker-compose-org1.yaml — copy to PC-2
  • docker-compose-org2.yaml — copy to PC-3

5) configure environmental variables in bymn.sh and ensure bymn.sh is same across all hosts

  • export ORDERER_HOSTNAME=<host name of PC-1>
  • export ORG1_HOSTNAME= <host name of PC-2>
  • export ORG2_HOSTNAME=<host name of PC-3>
  • export SWARM_NETWORK=”fabric” — Change it only if you want to create swarm network with different swarm network name
  • export DOCKER_STACK=”fabric” — Change it only if you want to create swarm network with different stack name

To get hostname run the following command

  • hostname

6) Create & setup Swarm

On PC-1

  • docker swarm init — advertise-addr <PC-1 IP address>
  • docker swarm join-token manager

Output of this command should be executed on PC-2 & PC-3 as follows

  • docker swarm join — token SWMTKN-1–3anjn4oxwcn278hie3413zaakr4higjdqr2x89r5605p1dosui-a4u407pt6c5ta2ont7pqdnm 137.116.147.36:2377 –advertise-addr <PC-2 Ip Address>
  • docker swarm join — token SWMTKN-1–3anjn4oxwcn278hie3413zaakr4higjdqr2x89r5605p1dosui-a4u407pt6c5ta2ont7pqdnm 137.116.147.36:2377 –advertise-addr <PC-3 Ip Address>

Replace token with the token you got in the previous command response

7) Create overlay network

on PC-1

  • docker network create — attachable — driver overlay fabric

8) Start Orderer

on PC-1

  • ./bymn.sh up -f docker-compose-orderer.yaml

Check the logs and make sure service is up.

9) Start CA1, Org 1 (Peer 0 & Peer 1) on PC-2

  • ./bymn.sh up -f docker-compose-org1.yaml

10) Start CA2, Org 2 (Peer 0 & Peer 1) on PC-3

  • ./bymn.sh up -f docker-compose-org2.yaml

Run docker service ls and make sure all services are running

This completes setup of Hyperledger fabric on multiple hosts

Test

To test network on PC-2 open cli

  • docker exec -it <docker cli name> bash

and run scripts/script.sh

If you see above success message in your console, then network setup is proper and is running correctly

Conclusion

This post gives an overview on setting up Hyperledger fabric on multiple hosts. One of the interesting project around this space is cello. project cello aims to bring the on-demand “as-a-service” deployment model to the blockchain ecosystem to reduce the effort required for creating, managing and terminating blockchains.

--

--