```yaml
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer1.org1.example.com:
peer0.org2.example.com:
peer1.org2.example.com:
networks:
byfn:
services:
orderer.example.com: #orderer节点的域名
extends: ##基于其他文件进行扩展
file: base/docker-compose-base.yaml #基于peer-base.yaml文件进行扩展
service: orderer.example.com #基于peer-base.yaml文件中的orderer.example.com服务进行扩展
container_name: orderer.example.com #容器名称
networks: #该节点所加入的网络
- byfn
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
networks:
- byfn
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
networks:
- byfn
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
networks:
- byfn
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org2.example.com
networks:
- byfn
cli: #peer节点客户端 之所以在这里有一个cli服务是因为,所有的交易都是从客户端发起的 需要用到User的证书
container_name: cli
image: hyperledger/fabric-tools:x86_64-1.0.0
tty: true
environment:
- GOPATH=/opt/gopath #docker容器启动之后,go的工作目录 不需要修改
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock #docker容器启动之后,对应的守护进程的本地套接字,不需要修改
- CORE_LOGGING_LEVEL=DEBUG #日志级别
- CORE_PEER_ID=cli #当前客户端的ID,自己指定
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 #与客户端相连的peer节点
- CORE_PEER_LOCALMSPID=Org1MSP #组织ID
- CORE_PEER_TLS_ENABLED=true #是否启用TLS加密通信技术
#证书文件
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# 私钥文件
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# 根证书文件
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
# 当前客户端节点的身份
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer #客户端节点工作目录
# command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT'
command: /bin/bash #这里原本是上面哪个commond的,但是我们还没编写scripts.sh脚本,所以先使用/bin/bash。不然如果给他指定了开启容器之后执行的任务的话,容器执行之后就会立马停掉,这是docker的知识点。
volumes:
- /var/run/:/host/var/run/
#链码路径的注入,我们在本地编写的智能合约(链码),都需要注入到cli这个服务中,然后通过cli进行向其他节点的分发,安装
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on: #指定多个服务之前的依赖关系.启动时会被先启动的依赖服务.以下就是在cli客户端服务启动前先启动的服务
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
networks: #cli客户端服务所加入的网络
- byfn
在docker-compose-cli.yaml文件中的服务有一个orderer节点,四个peer节点,以及一个cli节点。
其中orderer,peer都依赖于first-network/base目录下的docker-compose-base.yaml文件,和该文件其中的服务。
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
services:
#关注点:
#1.如何注入系配置到容器中 环境变量注入
#2.数据卷的映射
#3.端口的映射关系
orderer.example.com: #orderer节点域名
container_name: orderer.example.com
image: hyperledger/fabric-orderer:x86_64-1.0.0
environment: #关注点1.环境变量的注入
- ORDERER_GENERAL_LOGLEVEL=debug #日志级别,debug级别方便我们开发测试环境中进行调试
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 #orderer节点监听的地址(服务暴露地址)
- ORDERER_GENERAL_GENESISMETHOD=file #创世区块的来源,指定file来源就是文件
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block #创世区块对应的文件 上面一个和这一个统称注入创世区块
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP #Orderer节点所属的组织的ID
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp #当前节点的msp帐号
# enabled TLS TLS加密通信技术,我们是学习测试,不用到,直接注释掉
# - ORDERER_GENERAL_TLS_ENABLED=true #是否使用tls加密
# - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key 私钥
# - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt 证书
# - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] 根证书
working_dir: /opt/gopath/src/github.com/hyperledger/fabric #节点的工作目录
command: orderer #命令
volumes: #关注点2.数据卷映射,主机上的满足当前路径即可
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
- orderer.example.com:/var/hyperledger/production/orderer
ports: #关注点3,端口的映射
- 7050:7050 #将本机的7050端口映射成orderer节点的服务端口,前为主机端口,后为orderer节点端口
peer0.org1.example.com: #peer节点域名
container_name: peer0.org1.example.com #docker容器名称
extends: #基于其他文件进行扩展
file: peer-base.yaml #基于peer-base.yaml文件进行扩展
service: peer-base #基于peer-base.yaml文件中的peer-base服务进行扩展
environment: #环境变量的注入
- CORE_PEER_ID=peer0.org1.example.com #peer节点的名字,ID 随意起
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 #当前peer节点的地址信息
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 #peer节点外部端口,为了被其他节点感知到,如果不设置,别的节点不会知道有该节点的存在
- CORE_PEER_LOCALMSPID=Org1MSP #当前节点所属的组织的ID
volumes: #数据卷的映射,主机上的满足当前路径即可
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org1.example.com:/var/hyperledger/production
ports: #一个节点暴露两个端口
- 7051:7051 #grpc端口
- 7053:7053 #eventhub端口 用于事件监听
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1.org1.example.com
- CORE_PEER_ADDRESS=peer1.org1.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org1.example.com:/var/hyperledger/production
ports:
- 8051:7051
- 8053:7053
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.org2.example.com
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org2.example.com:/var/hyperledger/production
ports:
- 9051:7051
- 9053:7053
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1.org2.example.com
- CORE_PEER_ADDRESS=peer1.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org2.example.com:/var/hyperledger/production
ports:
- 10051:7051
- 10053:7053
docker-compose-base.yaml文件被docker-compose-cli.yaml文件所依赖。其实相当于是补充完善后者的orderer,和peer节点服务,有环境变量的配置,数据卷的映射,端口的映射(向本机暴露服务端口)。
同时此文件也依赖于peer-base.yaml文件。
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
services:
#peer的公共服务
peer-base: #因为peer节点比较多,所以将他们的公共参数都提取出来了,做成了一个公共服务
image: hyperledger/fabric-peer:x86_64-1.0.0 #节点的镜像版本
environment: #环境变量
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock #docker的本地套接字地址,不用修改
# the following setting starts chaincode containers on the same
# bridge network as the peers
# https://docs.docker.com/compose/networking/
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn #当前节点属于哪个网络,网络名字由docker-compose.yaml所在目录决定
#- CORE_LOGGING_LEVEL=ERROR #(也是将ChainCode的网络与peer节点的网络绑定到一起,jiusyhi使用同一个网络
- CORE_LOGGING_LEVEL=DEBUG #如果不设置这个环境变量,链码可能会连不上peer节点)
- CORE_PEER_TLS_ENABLED=true #是否使用TLS加密通信技术
- CORE_PEER_GOSSIP_USELEADERELECTION=true #释放自动选择leader节点
- CORE_PEER_GOSSIP_ORGLEADER=false #当前不是leader节点
- CORE_PEER_PROFILE_ENABLED=true #在peer节点中有一个profile服务
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer #所有再peer-base公共服务的节点的工作目录
command: peer node start #覆盖容器启动后默认执行的命令,也就是说容器启动之后先执行该命令
在docker-compose-base.yaml文件中我们可以看到,我们需要配置的节点很多,但其实他们有很多配置参数都是一样的,所以为了方便和统一,我们就可以直接弄一个peer公共服务。然后让docker-compose-base.yaml1文件依赖他就好了。
既然三个yaml文件都是有依赖关系的,那么我们何不如把它们整合为一个文件呢?
以docker-compose-base.yaml文件为核心。将其他需要用到的内容复过来,并把文件名中的“-base"去掉,为什么还要改个名字?懂的自然懂,了解过docker-compose编排工具的同学应该都知道,
当你up这个.yaml文件的时候,文件名叫docker-compose.yaml的好处。
docker-compose.yaml各组成部分的来源:
volumes,cli ——>docker-compose-cli.yaml
orderer和各个peer——>docker-compose-base.yaml
peer-base——>peer-base.yaml
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer1.org1.example.com:
peer0.org2.example.com:
peer1.org2.example.com:
services:
#关注点:
#1.如何注入系配置到容器中 环境变量注入
#2.数据卷的映射
#3.端口的映射关系
orderer.example.com: #orderer节点域名
container_name: orderer.example.com
image: hyperledger/fabric-orderer:x86_64-1.0.0
environment: #关注点1.环境变量的注入
- ORDERER_GENERAL_LOGLEVEL=debug #日志级别,debug级别方便我们开发测试环境中进行调试
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 #orderer节点监听的地址(服务暴露地址)
- ORDERER_GENERAL_GENESISMETHOD=file #创世区块的来源,指定file来源就是文件
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block #创世区块对应的文件 上面一个和这一个统称注入创世区块
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP #Orderer节点所属的组织的ID
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp #当前节点的msp帐号
# enabled TLS TLS加密通信技术,我们是学习测试,不用到,直接注释掉
# - ORDERER_GENERAL_TLS_ENABLED=true #是否使用tls加密
# - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key 私钥
# - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt 证书
# - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] 根证书
working_dir: /opt/gopath/src/github.com/hyperledger/fabric #节点的工作目录
command: orderer #命令
volumes: #关注点2.数据卷映射,主机上的满足当前路径即可
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
- orderer.example.com:/var/hyperledger/production/orderer
ports: #关注点3,端口的映射
- 7050:7050 #将本机的7050端口映射成orderer节点的服务端口,前为主机端口,后为orderer节点端口
peer0.org1.example.com: #peer节点域名
container_name: peer0.org1.example.com #docker容器名称
extends: #基于其他文件进行扩展
service: peer-base #基于peer-base服务进行扩展
environment: #环境变量的注入
- CORE_PEER_ID=peer0.org1.example.com #peer节点的名字,ID 随意起
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 #当前peer节点的地址信息
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 #peer节点外部端口,为了被其他节点感知到,如果不设置,别的节点不会知道有该节点的存在
- CORE_PEER_LOCALMSPID=Org1MSP #当前节点所属的组织的ID
volumes: #数据卷的映射,主机上的满足当前路径即可
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org1.example.com:/var/hyperledger/production
ports: #一个节点暴露两个端口
- 7051:7051 #grpc端口
- 7053:7053 #eventhub端口 用于事件监听
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
service: peer-base
environment:
- CORE_PEER_ID=peer1.org1.example.com
- CORE_PEER_ADDRESS=peer1.org1.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org1.example.com:/var/hyperledger/production
ports:
- 8051:7051
- 8053:7053
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
service: peer-base
environment:
- CORE_PEER_ID=peer0.org2.example.com
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org2.example.com:/var/hyperledger/production
ports:
- 9051:7051
- 9053:7053
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
service: peer-base
environment:
- CORE_PEER_ID=peer1.org2.example.com
- CORE_PEER_ADDRESS=peer1.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer1.org2.example.com:/var/hyperledger/production
ports:
- 10051:7051
- 10053:7053
peer-base:
image: hyperledger/fabric-peer:x86_64-1.0.0
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
# the following setting starts chaincode containers on the same
# bridge network as the peers
# https://docs.docker.com/compose/networking/
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=config_default
#- CORE_LOGGING_LEVEL=ERROR
- CORE_LOGGING_LEVEL=DEBUG
# - CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
# - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
# - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
# - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
cli: #peer节点客户端 之所以在这里有一个cli服务是因为,所有的交易都是从客户端发起的 需要用到User的证书
container_name: cli
image: hyperledger/fabric-tools:x86_64-1.0.0
tty: true
environment:
- GOPATH=/opt/gopath #docker容器启动之后,go的工作目录 不需要修改
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock #docker容器启动之后,对应的守护进程的本地套接字,不需要修改
- CORE_LOGGING_LEVEL=DEBUG #日志级别
- CORE_PEER_ID=cli #当前客户端的ID,自己指定
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 #与客户端相连的peer节点
- CORE_PEER_LOCALMSPID=Org1MSP #组织ID
- CORE_PEER_TLS_ENABLED=true #是否启用TLS加密通信技术
#证书文件
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# 私钥文件
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# 根证书文件
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
# 当前客户端节点的身份
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer #客户端节点工作目录
# command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT'
command: /bin/bash #这里原本是上面哪个commond的,但是我们还没编写scripts.sh脚本,所以先使用/bin/bash。不然如果给他指定了开启容器之后执行的任务的话,容器执行之后就会立马停掉,这是docker的知识点。
volumes:
- /var/run/:/host/var/run/
#链码路径的注入,我们在本地编写的智能合约(链码),都需要注入到cli这个服务中,然后通过cli进行向其他节点的分发,安装
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on: #指定多个服务之前的依赖关系.启动时会被先启动的依赖服务.以下就是在cli客户端服务启动前先启动的服务
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
最后启动网络:
cd到存放docker-compose.yaml文件的目录之下。
docker-compose.yaml up -d
-d 选项的作用是将网络启动的实时日志以守护进程的方式去执行,也就是后台运行。如果想看这个过程,就不填加它就好了。
docker ps -a
查看当前所有容器,看看是否网络正常启动了。
如果正常,那么则会有一下这些容器会是up状态:
root@Fabric1:~/go/src/github.com/hyperledger/fabric-samples/first-network# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8b923bcb27e hyperledger/fabric-tools:x86_64-1.0.0 "/bin/bash" 20 seconds ago Up 18 seconds cli
297773f70ca5 hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" 27 seconds ago Up 19 seconds 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
d4b84531d712 hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" 27 seconds ago Up 20 seconds net_peer-base_1
98bd256745d9 hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" 27 seconds ago Up 24 seconds 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
6e2e884f6290 hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" 27 seconds ago Up 22 seconds 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
e800d7476451 hyperledger/fabric-orderer:x86_64-1.0.0 "orderer" 27 seconds ago Up 21 seconds 0.0.0.0:7050->7050/tcp orderer.example.com
bc214b1b4e9f hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" 27 seconds ago Up 23 seconds 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
骚年啊,别以为这样就结束了,还是太 Too young!!!
启动网络其实有两方面的意思:
1.节点进程的启动,这个很简单,仅仅只需要配置好相应的参数,节点就算是启动起来了,但是这种网络是无法做任何的业务逻辑的。
第二种留在下一篇博客,好了,累了困了睡了。 有喜欢的记得点赞收藏关注哦。欢迎积极评论!!
2020年8月10日凌晨
整理于家中~~~