Block chain Hyperledger fabric environment to build CENTOS7 Docker environment

Source: Internet
Author: User
Tags docker ps hyperledger fabric

Operating Environment CENTOS7 64-bit

1. CentOS Docker Installation

Yum-y Install Docker-io

2. Start Docker Service

Start: Service Docker start

Boot from: Chkconfig Docker on

View Docker versions: Docker version

3. Installation container compose:

Curl-l https://github.com/docker/compose/releases/download/1.11.2/docker-compose-' uname-s '-' uname-m ' >/usr/ Local/bin/docker-compose
chmod +x/usr/local/bin/docker-compose

View the version number and display version information if the installation is successful:

Docker-compose version

4.docker Pull

Mkdir/opt/fabric

cd/opt/fabric/

Docker PULLYEASY/HYPERLEDGER-FABRIC:0.6-DP #拉取镜像
Docker tag Yeasy/hyperledger-fabric:0.6-dphyperledger/fabric-peer:latest #给镜像加标记
Docker tag YEASY/HYPERLEDGER-FABRIC:0.6-DP hyperledger/fabric-baseimage:latest
Docker tag YEASY/HYPERLEDGER-FABRIC:0.6-DP hyperledger/fabric-membersrvc:latest

Create a docker-compose.yml in the working directory

The contents are as follows:

MEMBERSRVC:
Image:hyperledger/fabric-membersrvc
Ports
-"7,054:7,054"
Command:membersrvc
VP0:
Image:hyperledger/fabric-peer
Ports
-"7,050:7,050"
-"7,051:7,051"
-"7,053:7,053"
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=true
-Core_security_enrollid=test_vp0
-CORE_SECURITY_ENROLLSECRET=MWYPMSRJUPBT
Links
-MEMBERSRVC
Command:sh-c "Sleep 5; Peer node start--peer-chaincodedev "


Running Compose mirrors

Docker-compose up-d

To view a running mirror

Docker PS

Enter Docker

Docker-compose exec  dockername bash
Peer Chaincode deploy-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02-c ' {' Function ': ' Init "," Args ": [" a "," M "," B "," 200 "]} '
(Parameter annotation-P: Specify Chaincode source path;-C: JSON format Shaincode code to execute)

The Chaincode name hash value is returned in the following figure red box, which means that the regional chain has been established successfully. The following can be tested and validated by CLI or post.

Compiling code

CD $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go

CP chaincode_example02/chaincode_example02.go $GOPATH/src/#复制目录里面的例2到 compiled $GOPATH/src/

CD $GOPATH/src/

Go build./chaincode_example02.go #编译成功会在GOPATH/src directory generation CHAINCODE_EXAMPLE02 file

(Chaincode_example02.go Source Link https://raw.githubusercontent.com/hyperledger/fabric/master/examples/chaincode/go/ CHAINCODE_EXAMPLE02/CHAINCODE_EXAMPLE02.GO)

b) Release Chaincode run under GOPATH/SRC

CORE_CHAINCODE_ID_NAME=MYCC core_peer_address=0.0.0.0:7051./chaincode_example02

Until the word "Received registered" appeared, the representative succeeded.



Block chain test:

I'm using the Restclient plugin installed by Firefox browser.

1. Login

Post Http://192.168.0.79:7050/registrar

{
"Enrollid": "Jim",
"Enrollsecret": "6avzqlwcue9b"
}

2. Deploy (Deployment)

Post Http://192.168.0.79:7050/chaincode

{

"Jsonrpc": "2.0",

"Method": "Deploy",

"Params": {

' Type ': 1,

"Chaincodeid": {

' Name ': ' MYCC '

},

"Ctormsg": {

"Function": "Init",

"Args": ["a", "1000", "B", "2000"]

},

"Securecontext": "Jim"

},

"id": 1

}

3. Invoke (Call)

Post Http://192.168.0.79:7050/chaincode

{
"Jsonrpc": "2.0",
"Method": "Invoke",
"Params": {
' Type ': 1,
"Chaincodeid": {
' Name ': ' MYCC '
},
"Ctormsg": {
"Function": "Invoke",
"Args": [
"A",
"B",
"100"
]
},
"Securecontext": "Jim"
},
"ID": 3
}

Regional information Query

Rest Way (Get HOST:7050/CHAIN/BLOCKS/1):

Host:7050/chain/blocks/0 is the Genesis block.

HOST:7050/CHAIN/BLOCKS/1 the first block, which was built when the DePoy was deployed

HOST:7050/CHAIN/BLOCKS/2 the second block, which was created when invoke transaction was invoked

To exit outside the mirror without closing the mirror:

Ctrl+p+q

Close Docker

Docker Stop Dockername

Note: If the above operation appears inexplicable problem, the first use of simple and rude way to restart the host, if not resolved, in the other way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.