BlockChain Apps Deployment using Microservices With Dockers

BlockChain on Docker

What is a BlockChain?

Blockchain is a distributed database that maintains a continuously-growing list of ordered records called blocks. This technology underlying Bitcoin and other cryptocurrencies. It is a public ledger of all Bitcoin transaction. These blocks are added in a chronological order. In order to deploy a Blockchain application, you need a distributed Hyperledger Blockchain on your choice of infrastructure (on-premise or cloud).

blockchain technology

In this article we will deploy a Hyperledger Fabric cluster using Docker.

Prerequisites

To follow this guide you need a system with working Docker engine and docker-compose on it. We will use Fabric which is an implementation of Blockchain technology written in Golang, so go version go1.6.2 or above is required. Before proceeding further let’s have a look on Hyperledger Fabric.

The HyperLedger Project

Hyperledger is an open source project with collaborative effort created to advance Blockchain technology. It helps in cross-industry distributed ledgers which support transaction system, property transaction, and other services.

HyperLedger Fabric

Fabric is an implementation of blockchain technology. It provides a modular architecture allowing pluggable implementations of the various function.

Setting HyperLedger Cluster

Pulling Images

First, pull the latest images published by the Hyperledger fabric project from DockerHub.

docker pull hyperledger/fabric-peer:latest

docker pull hyperledger/fabric-membersrvc:latest

Now in order to run these images. Create a docker-compose file which will launch both of these services.


membersrvc:
image: hyperledger/fabric-membersrvc
ports:
- "7054:7054"
command: membersrvc
vp0:
image: hyperledger/fabric-peer
ports:
- "7050:7050"
- "7051:7051"
- "7053:7053"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
- CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
- CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
- CORE_SECURITY_ENABLED=false
- CORE_SECURITY_ENROLLID=test_vp0
- CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
links:
- membersrvc
command: sh -c "sleep 5; peer node start --peer-chaincodedev"

 

That’s it now we are ready to launch these service by simply running docker-compose up

 

blockchain technology

Running the ChainCode

Before running chaincode you need to set your $GOPATH and then make a directory to download the sample chaincode in the src directory.


mkdir -p $GOPATH/src/github.com/chaincode_example02/
cd $GOPATH/src/github.com/chaincode_example02
Curl --request GET https://raw.githubusercontent.com/hyperledger/fabric/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go > chaincode_example02.go

Next, you’ll need to download the Hyperledger fabric to your local $GOPATH, after that you have to build the chaincode.


mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
git clone http://gerrit.hyperledger.org/r/fabric

Go to chaincode_example02 directory and build the code


cd $GOPATH/src/github.com/chaincode_example02
go build

Starting And Registering The ChainCode

Run the following command to start the chaincode.


CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:7051 ./chaincode_example02

After that chaincode console will display the message “Received REGISTERED, ready for invocations” which shows that chaincode is ready for use.

blockchain technology

 

Running Rest API

Running Rest API

To log in with the help of REST API, send a POST request to the /registrar endpoint, with the enrollment ID and enrollment PW. These parameters are listed in the eca.users section of the membersrvc.yaml file.

REST Request:


POST localhost:7050/registrar

{
"enrollId": "jim",
"enrollSecret": "6avZQLwcUe9b"
}

REST Response:

200 OK
{
"OK": "Login successful for user 'jim'."
}

 

Read The Full Article At: XenonStack.com/blog

Advertisements

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