Stand up Orderer node using orderer.yaml and docker in Fabric v1.4
In this article, we will see how to bring up an orderer by configuring the orderer.yaml file and docker yaml files using fabric-samples 1.4.x.
There are few ways to stand up/bring up an orderer(ordering service) out of which using orderer.yaml file is one of them.
If you already have fabric setup done, go ahead and jump to Step 2.
Step 1: Fabric setup
If not done so, run the below command to pull fabric-samples code, binaries, config files and images for the specified version. In this case we have specified Fabric v1.4.8.
curl -sSL http://bit.ly/2ysbOFE | bash -s -- 1.4.8 1.4.8 0.4.21
Once complete, the fabric-samples will be present in the directory from which the above command is executed. config folder within fabric-samples contains 3 yaml files namely configtx.yaml, core.yaml and orderer.yaml.
core.yaml is used by peers and orderers use orderer.yaml. Necessary changes has to be done in order for peer and orderer to bootstrap with the core.yaml and orderer.yaml files respectively.
There are various configurations in the orderer.yaml, however we will see how to bootstrap the orderer with a genesis block.
Step 2: Copy orderer.yaml into first-network directory
Copy the orderer.yaml folder into first-network directory.
Step 3: Generate artifacts
From the first-network directory, run the below command which creates required certificates and channel artifacts.
A genesis block file named genesis.block gets created within channel-artifacts folder which uses TwoOrgsOrdererGenesis profile (solo orderer) as specified in the script.
Step 4: Create new genesis block
We will generate a new genesis block file to use SampleMultiNodeEtcdRaft profile in configtx.yaml which is a raft setup. You can even use Kafka profile if required. Make sure that the bin folder is present inside fabric-samples directory. Run the following command from first-network directory.
../bin/configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesisA.block
This creates a genesis file named genesisA.block within channel-artifacts. Let’s use this genesis file to bootstrap the orderer.
Note that the channel-artifacts folder also contains a file named genesis.block as a result of running the ./byfn.sh generate command earlier. Delete this file as it is of no use for us in this case.
Step 5: Configure docker YAML files
GenesisFile variable in orderer.yaml points to FABRIC_CFG_PATH environment variable by default. By default, the FABRIC_CFG_PATH is pointed to /etc/hyperledger/fabric path inside the orderer’s docker container.
Note: If we need to use orderer.yaml to bootstrap the orderer, we need to create a volume and mount it to the path where orderer.yaml file is present.
The base folder contains docker-compose-base.yaml and peer-base.yaml.
In docker-compose-base.yaml, add a volume and mount the directory path of orderer.yaml with default FABRIC_CFG_PATH of orderer.
Since genesis block file resides in channel-artifacts folder and orderer.yaml file is present within first-network folder, we will mount first-network directory to FABRIC_CFG_PATH of orderer.
In peer-base.yaml file, comment or remove the highlighted environment variable shown below.
Step 6: Configure orderer.yaml file
Change the orderer.yaml present in the path as shown below. Orderer uses this configuration during bootstrap.
Now the orderer will bootstrap with the genesisA.block file and SampleMultiNodeEtcdRaft profile. We can change other variables as well if we want to do so. But we will keep things simple in this article.
Lastly, spin-up the docker container of just orderer using below command.
docker-compose -f docker-compose-cli.yaml up -d orderer.example.com
If everything goes fine, the orderer container will be created successfully. We can check the docker logs to find out whether our configuration is applied or not.
We can see that our configuration for genesis block is applied during bootstrap.
The orderer is now using Raft consensus as specified in orderer.yaml.
Note: Just as we configured orderer with genesis block, we can do all sorts of configurations which is supported by orderer.yaml config file.
P.S: Hope this article was helpful to you in some way. If you like the article, please give a clap.
Please let me know for any suggestions or corrections :) Cheers !