操作系统:Ubuntu 16.04
软件包:Hyperledger/fabric 1.0.0
以下命令要用root执行,或者使用sudo
apt install curl
curl -fsSL https://get.docker.com/ | sh
修改Docker配置文件/etc/default/docker,增加下面内容
DOCKER_OPTS="--registry-mirror=http://a82cc970.m.daocloud.io"
这是国内镜像,否则docker pull的时候会很慢很慢
//启动服务
systemctl daemon-reload
systemctl restart docker.service
如果遇到启动错误,如:
Failed to start Docker.service: Unit docker.service is masked.
执行下面的命令,再启动docker.service
systemctl unmask docker.service
systemctl unmask docker.socket
apt install python-pip
pip install docker-compose>=1.8.0
docker pull yeasy/hyperledger-fabric-base:0.8.4
docker pull yeasy/hyperledger-fabric-peer:0.8.4
docker pull yeasy/hyperledger-fabric-orderer:0.8.4
docker pull yeasy/hyperledger-fabric-ca:0.8.4
docker pull yeasy/blockchain-explorer:latest
docker tag yeasy/hyperledger-fabric-peer:0.8.4 hyperledger/fabric-peer
docker tag yeasy/hyperledger-fabric-orderer:0.8.4 hyperledger/fabric-orderer
docker tag yeasy/hyperledger-fabric-ca:0.8.4 hyperledger/fabric-ca
docker tag yeasy/hyperledger-fabric-base:0.8.4 hyperledger/fabric-baseimage
docker tag yeasy/hyperledger-fabric-base:0.8.4 hyperledger/fabric-ccenv:x86_64-1.0.0-preview
docker tag yeasy/hyperledger-fabric-base:0.8.4 hyperledger/fabric-baseos:x86_64-1.0.0-preview
也可以使用官方镜像
https://hub.docker.com/r/hyperledger
下载 Compose 模板文件
git clone https://github.com/yeasy/docker-compose-files
在根目录会生成docker-compose-files文件夹
进入/docker-compose-files/hyperledger/1.0目录,模板文件功能如下:
peers.yml:包含 peer节点的服务模板。
docker-compose.yml:启动1个最小化的环境,包括1个peer节点、1个Orderer节点、1个CA节点。
通过如下命令快速启动。
docker-compose up
但是执行这个命令有错误,修改了docker-compose.yml中peer的command,将 -o orderXXX去掉了
查看容器
docker ps
连接容器
docker exec -it fabric-peer0 bash
连接后,部署一个测试程序
peer chaincode install -n test_cc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a","100","b","200"]}' -v v0
peer chaincode instantiate -n test_cc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a","100","b","200"]}' -v v0
peer chaincode query -n test_cc -c '{"Args":["query","b"]}'
如果提示下面的错误:
Error: Error endorsing invoke: rpc error: code = 2 desc = failed to obtain cds for test_cc - transaction
not found test_cc/testchainid
可能是因为没有执行 instantiate操作
如果提示下面的错误:
Error: Error endorsing chaincode: rpc error: code = 2 desc = Error installing chaincode code test_cc:1.0(chaincode
/var/hyperledger/production/chaincodes/test_cc.1.0 exits)
可能文件已经存在,可以移除再重新创建
docker rmi 库的名字
a向b转账10
peer chaincode invoke -n test_cc -c '{"Args":["invoke","a","b","10"]}'