Getting started with the Hyperledger Fabric docker images on a Linux Mint virtual image

Introduction

If you tried the instructions to get started with the Hyperledger Fabric docker images here on a Windows box, you probably ran into issues with Docker and a bash shell just like I did.

There is a much better way. I installed everything on a nice Linux Mint 18 Vagrant virtual image which is even friendlier than my customized Windows 7 dev workstation. I will describe the step by step procedure below.

Please note that I will refer to the linked document above from time to time by “quoting passages” in purple italic. This should help you match what I am doing with the reference guide.

 

Assumptions

  • You have followed all the steps to install Vagrant and Cygwin as described in my first post, right up to and including the section “Test Go in Cygwin”;
  • You are comfortable using a Linux command prompt.

 

Steps we will follow

  • Getting a Vagrant Linux Mint virtual image
  • Install Docker pre-requisites on the Linux Mint virtual image
  • Install Docker
  • Test Docker
  • Edit the C:\gocode\mint\Vagrantfile so the Mint GUI opens up without messing in Oracle Virtualbox
  • Install Hyperledger-Fabric on the Linux Mint image
  • Install Docker-Compose
  • Run the Hyperledger-Fabric Demo
  • Create a custom channel
  • Peer “a” has 100 units to start with, transfers 10 units to Peer “b”, and ends up with 90 units
  • Final note

 

Getting a Vagrant Linux Mint virtual image

Open a Cygwin prompt on your Windows computer. Type commands:

cd /cygdrive/c/gocode

mkdir mint

cd mint

vagrant init tcoursen3/baseMint; vagrant up –provider virtualbox

This will take a while. And thank you very much, tcoursen3, I love your Linux Mint vagrant box!

Next, once the virtual image is up and running, log in to it using command:

vagrant ssh

First, change the vagrant user password so you can log in through the GUI:

sudo passwd vagrant

At this point, you can launch the GUI if you want by going to the Windows Start button > Oracle Virtualbox > selected the Mint vm > click the Show button

Log in with user “vagrant” and the new password you provided above.

 

Install Docker pre-requisites on the Linux Mint virtual image

Either still on the Cygwin SSH prompt or in a new terminal opened in the Mint GUI, do the command:

sudo apt-get install software-properties-common python-software-properties libapparmor1 libltdl7 wget curl build-essential apt-transport-https ca-certificates golang dos2unix openssl

Import the GPG key:

sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Next, point the package manager to the official Docker repository:

sudo apt-add-repository ‘deb https://apt.dockerproject.org/repo ubuntu-xenial main’

Update the package database:

sudo apt update

Install both following packages to eliminate an unmet dependencies error:

sudo apt install linux-image-generic linux-image-extra-virtual

Reboot the system so it would be running on the newly installed kernel image:

sudo reboot

 

Install Docker

In a terminal, run the following commands:

sudo apt install docker-engine

sudo usermod -aG docker vagrant

sudo usermod -aG docker root

sudo reboot

 

Test Docker

In a terminal, run command:

sudo docker run hello-world

You will get a hello from Docker:

11.png

At this point, since we have rebooted outside of Vagrant and might have lost the synchronization between the host folder /cygdrive/c/gocode/mint to the Linux /vagrant folder, go to the Cygwin prompt and do command:

vagrant halt

 

Edit the C:\gocode\mint\Vagrantfile so the Mint GUI opens up without messing in Oracle Virtualbox

Edit out the # for the following lines in a text editor (I like Notepad++ on Windows), add some memory so the following block looks like this:

20.png

Save the Vagrantfile.

Next, boot the VM:

vagrant up

It opens as if by magic.

22.png

 

Install Hyperledger-Fabric on the Linux Mint image

Log in to Linux Mint, open a terminal. Do commands:

cd /vagrant

mkdir fabric-sample

cd fabric-sample

sudo curl -sSL https://goo.gl/LQkuoh | bash

sudo reboot

Go to the Cygwin prompt and do command:

vagrant reload

 

Install Docker-Compose

Still a missing piece in the puzzle (ref).

Launch the Mint GUI by Windows Start button > Oracle Virtualbox > selected the Mint vm > click the Show button

Log in to Linux Mint, open a terminal. Do commands:

cd /vagrant

mkdir docker-compose

cd docker-compose

sudo wget -L https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-`uname -s`-`uname -m`

cd /usr/bin

sudo ln -s /vagrant/docker-compose/docker-compose-Linux-x86_64 .

Run the Hyperledger-Fabric Demo

cd /vagrant/fabric-sample/release/linux-amd64/

Run the demo script, which “leverages these docker images to quickly bootstrap a Fabric network, join peers to a channel, and drive transactions (running) an end-to-end sample application.

sudo ./network_setup.sh up

 

Create a custom channel

To create a custom channel, first stop the “private network”:

./network_setup.sh down

Next, “generate the cryptographic material (x509 certs) for our various network entities” using a new, unique channel name:

./generateArtifacts.sh bertrandszoghychannel

Open a text file editor, open file docker-compose-cli.yaml and edit out the line by adding a # at the beginning:

command: /bin/bash -c ‘./scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT’

Launch docker-compose:

CHANNEL_NAME=bertranszoghychannel TIMEOUT=6000 docker-compose -f docker-compose-cli.yaml up

Open a second terminal window. Do commands:

cd /vagrant/fabric-sample/release/linux-amd64/

docker exec -it cli bash

If successful you should see the following:

root@0d78bb69300d:/opt/gopath/src/github.com/hyperledger/fabric/peer#

You are now living in a docker Linux microservice which is living in a Linux virtual image living on a Windows host.

Next command is:

peer channel create -o orderer.example.com:7050 -c bertrandszoghychannel -f ./channel-artifacts/channel.tx –tls $CORE_PEER_TLS_ENABLED –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem

This will give you something like this:

12.png

If you do command:

ls

You will see a new bertrandszoghychannel.block file was created.

Next, join the channel with command:

peer channel join -b bertrandszoghychannel.block

Result should look like this:

13.png

Next, “install the sample go code onto one of the four peer nodes. This command places the source code onto our peer’s filesystem“:

peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

This will be the result:

15.png

Next, instantiate the chaincode on the channel. This will initialize the chaincode on the channel, set the endorsement policy for the chaincode, and launch a chaincode container for the targeted peer“:

peer chaincode instantiate -o orderer.example.com:7050 –tls $CORE_PEER_TLS_ENABLED –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -C bertszoghychannel -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c ‘{“Args”:[“init”,”a”, “100”, “b”,”200″]}’ -P “OR (‘Org1MSP.member’,’Org2MSP.member’)”

Result of that one:

16.png

 

Peer “a” has 100 units to start with, transfers 10 units to Peer “b”, and ends up with 90 units

Let’s query for the value of a to make sure the chaincode was properly instantiated and the state DB was populated“:

peer chaincode query -C bertrandszoghychannel -n mycc -c ‘{“Args”:[“query”,”a”]}’

My result was:

17.png

Next, “let’s move 10 from a to b. This transaction will cut a new block and update the state DB“:

peer chaincode invoke -o orderer.example.com:7050 –tls $CORE_PEER_TLS_ENABLED –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -C bertrandszoghychannel -n mycc -c ‘{“Args”:[“invoke”,”a”,”b”,”10″]}’

Result:

18

Finally, we query again. “Let’s confirm that our previous invocation executed properly. We initialized the key a with a value of 100 and just removed 10 with our previous invocation. Therefore, a query against a should reveal 90“:

peer chaincode query -C bertrandszoghychannel -n mycc -c ‘{“Args”:[“query”,”a”]}’

Result:

19.png

Success! We have transferred 10 units and saved the transaction to our blockchain.

 

Final note

I liked this Linux Mint 18 image so much that I installed Visual Studio Code with NodeJs on it, with a standalone CouchDB, and learned to run Map/Reduce queries. Admittedly one of the nicest development environments I’ve ever used. The details in my next post.

 

Bertrand Szoghy,

June 2017

Advertisements

2 thoughts on “Getting started with the Hyperledger Fabric docker images on a Linux Mint virtual image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s