How can I set up hyperledger fabric with multiple hosts using Docker?
I found a solution that seems to work using docker swarm mode.
- Initialize a swarm: (docker swarm documentation for mor information)
- Join the swarm with the other host as a manager
Create a network ("hyp-net" in my case)
docker network create --attachable --driver overlay hyp-net
Changes I had to do:
- Linked the containers with the --link docker parameter
- Added the --network docker parameter (--network=hyp-net)
Added a new environment varialble todocker run command used:
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net
Here are the commands that works for me:
Orderer
docker run --rm -it --network="hyp-net" --name orderer -p 8050:7050
-e ORDERER_GENERAL_LEDGERTYPE=ram
-e ORDERER_GENERAL_BATCHTIMEOUT=10s
-e ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT=10
-e ORDERER_GENERAL_MAXWINDOWSIZE=1000
-e ORDERER_GENERAL_ORDERERTYPE=solo
-e ORDERER_GENERAL_LOGLEVEL=debug
-e ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
-e ORDERER_GENERAL_LISTENPORT=7050
-e ORDERER_RAMLEDGER_HISTORY_SIZE=100
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net
sfhackfest22017/fabric-orderer:x86_64-0.7.0-snapshot-c7b3fe0 orderer
Peer0
docker run --rm -it --link orderer:orderer --network="hyp-net" --name peer0 -p 8051:7051 -p 8053:7053
-v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer0:/etc/hyperledger/fabric/msp/sampleconfig
-e CORE_PEER_ADDRESSAUTODETECT=true
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
-e CORE_LOGGING_LEVEL=DEBUG
-e CORE_PEER_NETWORKID=peer0
-e CORE_NEXT=true
-e CORE_PEER_ENDORSER_ENABLED=true
-e CORE_PEER_ID=peer0
-e CORE_PEER_PROFILE_ENABLED=true
-e CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050
-e CORE_PEER_GOSSIP_ORGLEADER=true
-e CORE_PEER_GOSSIP_IGNORESECURITY=true
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net
sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false
Peer1
docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false
Peer2
docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 --link peer1:peer1 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false
Cli
docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 --link peer1:peer1 --link peer2:peer2 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 ./channel_test.sh
With this, I am able to deploy, invoke and query my chaincode.
I was able to host hyperledger fabric network on multiple machines using docker swarm mode. Swarm mode provides a network across multiple hosts/machines for the communication of the fabric network components.
This post explains the deployment process.It creates a swarm network and all the other machines join the network. https://medium.com/@wahabjawed/hyperledger-fabric-on-multiple-hosts-a33b08ef24f
It works with Fabric 1.0+