Hyperledger Fabric explained - docker-compose.yml
#1
In order to configure and launch your own Hyperledger fabric network, you will need 3 files 

-configtx.yaml

-crypto-config.yaml

-docker-compose.yml

This tutorial try to explain how, the docker-compose.yml file is structured. 

For each entity on our network we need a diffent docker container. 

We will see how to declare : 

-Certificate authority container
-Peer container
-Couchdb container
-Orderer container
-Kafka container (network using kafka)
-Zookeeper container (network using kafka)


Header :

First of all, we have to declare a new network.

[Image: 1538568532.png]

Certificate Authority :

For each organization on our network, we need a CA container following this structure.


[Image: 1538568647-docker-compose0.png]

Hostname :

                image : hyperledger/fabric-ca :$ARCH-1.1.0 ($ARCH correspond to your system export it using « export ARCH=$(arch) »)

                environment : (environnement variable)

                               -FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server

                               -FABRIC_CA_SERVE_CA_NAME=hostname

                ports :

                               - « 7054 :7054 » (use « 8054 :7054 » for your next CA container, « 9054 :7054 » for your third…)

                command : sh -c 'fabric-ca-server start –ca.certfile /etc/hyperledger/fabric-ca-server-config/your_hostname.com-cert.pem –ca.keyfile /etc/hyperledger/fabric-ca-server-config/*_sk -b admin :adminpw’

                volumes : (allow our container to acces « ./crypto-config/peerOrganizations/your_hostname » directory)

                              - ./crypto-config/peerOrganizations/your_hostname/ca/:/etc/hyperledger/fabric-ca-server-config

                container_name : your_hostname

                networks :
                                - Your network previously declared

Peer :

For each peer, we need to create a container following this structure.

[Image: 1538568925-docker-compose5.png]
hostname: [i](peer + number + .org.com)
[/i]

    container_name: hostname

    image: hyperledger/fabric-peer:$ARCH-1.1.0

    environment:

      - CORE_LOGGING_LEVEL=debug

      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock

      - CORE_PEER_ID=hostname

      - CORE_PEER_ADDRESS=hostname

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=$NETWORK_NAME

      - CORE_PEER_LOCALMSPID=MSP name (defined on configtx.yaml)

      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/msp

      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB (required to use Couchdb)

      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984 (required to use Couchdb)

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric

    command: peer node start

    ports:

      - 7051:7051 (use «8051 :7051 » for your next peer container, « 9051 :7051 » for your third…)

      - 7053:7053 (use «8053 :7053 » for your next peer container, « 9053 :7053 » for your third…)

 

    volumes:

        - /var/run/:/host/var/run/

        - ./channel-artifacts:/etc/hyperledger/configtx

        - ./crypto-config/peerOrganizations/hostname/peers/hostname/msp:/etc/hyperledger/peer/msp

        - ./crypto-config/peerOrganizations/hostname/users:/etc/hyperledger/msp/users

    depends_on:

      - orderer.example.com

      - couchdb (couchdb instance for our peer ex : couchd1)

    networks:

      - Your network previously declared

 
Couchdb :

You must set a couchdb instance for each peer on your network.

[Image: 1538569072-docker-compose4.png]

name: [i](couchdb + number)
[/i]

    container_name: name

    image: hyperledger/fabric-couchdb:$ARCH-0.4.6

    ports:

      - 5984:5984 (use «6984 :5984 » for your next couchdb container, « 7984 :5984 » for your third…)

    environment:

      DB_URL: http://localhost:5984/member_db  (use http://localhost:6984/member_db for your next couchdb )

    networks:
      - Your network previously declared

Orderer :

[Image: 1538569151-docker-compose3.png]

  name:

    container_name: name

    image: hyperledger/fabric-orderer:$ARCH-1.1.0

    environment:

      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092,kafka3:9092]

      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s

      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s

      - ORDERER_KAFKA_VERBOSE=true

      - ORDERER_GENERAL_LOGLEVEL=debug

      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0

      - ORDERER_GENERAL_GENESISMETHOD=file

      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block (link to your genesis block)

      - ORDERER_GENERAL_LOCALMSPID=MSP NAME

      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric

    command: orderer

    ports:

      - 7050:7050 (use «8050:7050 » for your next couchdb container, « 9050:7050 » for your third…)

    volumes:

        - ./channel-artifacts:/etc/hyperledger/configtx  (the channel-artifacts folder will be know as /etc/hyperledger/configtx folder by docker)

        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/etc/hyperledger/msp/orderer/msp

    depends_on:

        - kafka0

        - kafka1

        - kafka2

        - kafka3

    networks:
      - Your network previously declared

Kafka :

Number of kafka should be set to 4. (This is the minimum number of nodes necessary in order to exhibit crash fault tolerance, i.e. with 4 brokers, you can have 1 broker go down, all channels will continue to be writeable and readable, and new channels can be created.)

[Image: 1538569141-docker-compose2.png]

For each of our 4 kafka instance, we need this structure :
Name : (kafka + number)
            extends : (docker will look at the docker-compose-base.yml file in order to get full config))
                               file : docker-compose-base.yml
                               service : kafka
            container_name : name
            environment :
                 - KAFKA_BROKER_ID=0 (1 for the next one then 2 …)
                 - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
                 - KAFKA_MESSAGE_MAX_BYTES=103809024
                 - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
                 - KAFKA_REPLICA_FETCH_RESPONSE_MAX_BYTES=103809024
            depends_on :
                - zookeeper0
                - zookeeper1
                - zookeeper2
            networks :
                - Your network previously declared

Zookeeper :

Zookeeper number will either be 3, 5, or 7. It has to be an odd number to avoid split-brain scenarios, and larger than 1 in order to avoid single point of failures. Anything beyond 7 ZooKeeper servers is considered an overkill.

[Image: 1538569467-docker-compose1.png]

 name: (zookeeper + number)
    extends:
        file: docker-compose-base.yml
        service: zookeeper
    container_name: name
    environment:
        - ZOO_MY_ID=1  (1 for the next one then 2 …)
        - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
    networks:
      - Your network previously declared
Reply
#2
Awesome tutorial. Thanks for the contributions. I am still learning native Fabric myself so this will come in handy!
Reply
#3
Nihcep -
Thanks for the breaking this down, great for (us) starting out.
Question for the thread - I'm assuming the environment paths suggested are would NOT be used for the tutorial builds - byfn etc. ? And if one is creating or extending those tutorials, expect the paths to start relative to "~/fabric-samples" ?
thx in advance for any pointers
Reply
#4
(10-22-2018, 04:34 PM)jtwalker2000 Wrote: Nihcep -
Thanks for the breaking this down, great for (us) starting out.
Question for the thread - I'm assuming the environment paths suggested are would NOT be used for the tutorial builds - byfn etc. ? And if one is creating or extending those tutorials, expect the paths to start relative to "~/fabric-samples" ?
thx in advance for any pointers

I'm not sure to understand the question, but you can use theses file from anywhere, it is absolute path.
Reply