This is my first multi-host setup for Hyperledger Fabric. It is a setup of two organizations with four peers, and three orderer services using Docker Swarm as the multi-host container environment. We first make an introduction to Docker Swarm. With that, we go through the steps, bringing up this fabric network in a two-host network in an AWS environment.
Docker Swarm is a container orchestration tool natively in the Docker environment. In a nutshell, It provides an overlay network for containers across multiple hosts. Those containers on this overlay network can communicate to one another as if they were on a large host. The good side, obviously, is that the original configuration can be used with minimal modification, and no static information such as IP is coded in the configuration. In this article, we are using Docker Swarm.
This tutorial requires you to clone my Github code from here. https://github.com/AnanthaKannan/BasicNetwork-2.x
- docker 19.x.x
- docker-compose 1.x.x
- Basic-Network (clone the GitHub code)
We distribute these containers into two hosts. Here we are using two EC2 running in AWS. Like other demonstrations, we do not use any features on AWS, just purely EC2 instances with Ubuntu and the required software. Communication is through public IP.
PC -1 (Org -1)
- A Certificate Authority (CA)
- 2 Peers (peer0.org1.exampl.com, peer1.org1.example.com)
- 2 Orderers (orderer0.example.com, orderer1.example.com)
PC -2 ( Org-2)
- A Certificate Authority (CA)
- 2 Peers (peer0.org2.exampl.com, peer1.org2.example.com)
- 3 Orderers (orderer2.example.com)
- Bring up two AWS EC2 instances with proper fabric prerequisites tools and images.
- Form an overlay network and make all the two hosts join.
- Prepare everything on Host 1, including the crypto material, channel configuration transactions, docker-compose files for each node. Then copy the whole structure to all other hosts.
- Bring up all components with docker-compose files.
- Create a channel and join all the peers to mychannel.
- Install and instantiate Fabcar chaincode.
- Invoke and query chaincode functions.
STEP 1: Bring Up Hosts
I am using AWS EC2 t2.small instances. I have preloaded the docker and docker-compose in all instances. Release hyper-ledger 2.0 is used in this demo.
Note that for demo purposes I have a security group opening for everything (all UDP, TCP, and ICMP). For production make sure you just open the ports needed.
Note: The following port must be open for Docker-swarm
1. 2377 (TCP) — Cluster management
2. 7946 (TCP and UDP) — Node Communication
3. 4789 (TCP and UDP) — Overlay network traffic
Step 2: Form an Overlay Network with Docker Swarm
Now we can open four terminals, one for each pc.
ssh -i <key> ubuntu@<public IP>
From PC 1,
docker swarm init --advertise-addr <pc-1 ip address>docker swarm join-token manager
Use the last output, add other hosts as manager to this swarm.
From PC -2
<output from join-token manager> --advertise-addr <pc-2 ip address>
docker network create --attachable --driver overlay basic-network docker network ls
docker network ls
Finally, we add an overlay basic-network, which will be the network for our demo. This is only done on one node. If Docker Swarm works correctly, all nodes will have this overlay network. docker network ls to verify the overlay-network
Step 3: Prepare Fabric Network Material in PC -1 and Copy to Others
One of the critical parts is to make sure all components are sharing the same crypto material. We will use pc -1 to create the material and copy them to other hosts.
In theory, we only need to ensure identity (certificates and signing keys) follow the scheme required. Certificates for an organization (e.g. org1) are issued and signed by the same CA (ca.org1). This is ensured by the use of cryptogen. For sake of simplicity, in this demo we create all the material in PC -1, and the whole directory crypto-config is then copied to other hosts.
Step 4: Bring Up Containers in Each Host
We use docker-compose to bring up all hosts.
# from PC -1,
docker-compose -f pc1.yaml up -d# from PC -2,
docker-compose -f pc2.yaml up -d
Step 5: Create Channel and All Peer Nodes Join It
As we only have CLI on PC-1, all commands are issued from PC -1 terminal.
Step 6: Install and Instantiate Fabcar Chaincode
From PC -1 terminal,
Install Fabcar chaincode to all peer nodes
Step 7: Chaincode Invoke and Query
For demonstration and according to Fabcar design, we first invoke initLedger function to preload10 car records in the ledger.
In this demonstration, we build two organizations with basic network. These containers are running in two separate PC’s. Docker Swarm brings these two PC’s together such that containers running in different PC’s can communicate. We no longer specify static IP on fabric network components, and all containers talk to one another as if they were on the same host.Anantha KannanFollow