【Hyperledger Fabric 开发学习3.5】 docker-compose 文件解析

这是一个HyperledgerFabric网络的docker-compose配置文件示例,包含了orderer节点和多个组织的peer节点的详细设置,包括端口映射、环境变量、证书路径和网络配置等。该文件用于在Docker容器中启动和连接区块链网络。
摘要由CSDN通过智能技术生成

编写 orderer 节点 docker-compose 文件

version: '2.0'

volumes:
  orderer.example.com:
  peer0.org1.example.com:
  peer1.org1.example.com:
  peer0.org2.example.com:
  peer1.org2.example.com:

network:
  testwork
  
services:
  orderer.example.com:
    image: hyperledger/fabric-orderer:2.0
    container_name: orderer0.example.com
    environment:
        - FABRIC_LOGGING_SPEC=INFO
        - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # default: 127.0.0.1
        - ORDERER_GENERAL_LISTENPORT=7050
        - ORDERER_GENERAL_GENESISMETHOD=file # default: provisional
        - ORDERER_GENERAL_BOOTSTRAPFILE=/etc/hyperledger/fabric/orderer.genesis.block # by default, all materials should be put under $FABRIC_CFG_PATH, which defaults to /etc/hyperledger/fabric
        - ORDERER_GENERAL_LOCALMSPID=OrdererMSP # default: DEFAULT
        - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/fabric/msp
       # enabled TLS
        - ORDERER_GENERAL_TLS_ENABLED=true # default: false
        - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/fabric/tls/server.key
        - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/fabric/tls/server.crt
        - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/fabric/tls/ca.crt]
        - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/etc/hyperledger/fabric/tls/server.key
        - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/etc/hyperledger/fabric/tls/server.crt
        - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/etc/hyperledger/fabric/tls/ca.crt]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
      - ./channel-artifacts/orderer.genesis.block:/etc/hyperledger/fabric/orderer.genesis.block
      - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/:/etc/hyperledger/fabric/tls
      - orderer.medical.com: /var/hyperledger/production/orderer
    ports:
      - "7050:7050"
    network:
     testwork

peer0.org1.example.com:
  image: hyperledger/fabric-peer:2.0
  container_name: peer0.org1.example.com
  environment:
    #- CORE_PEER_ADDRESSAUTODETECT=false
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock  
    - CORE_PEER_ID=peer0.org1.example.com
    - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7061
    - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
    - CORE_PEER_LOCALMSPID=Org1MSP
    - FABRIC_LOGGING_SPEC=INFO
    #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to 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
    - core_CHAINCODE_EXECUTETIMEOUT=300ms
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: peer node start
  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
      - 7052:7052
      - 7053:7053
  network:
    testwork

peer1.org1.example.com:
  image: hyperledger/fabric-peer:2.0
  container_name: peer1.org1.example.com
  environment:
    #- CORE_PEER_ADDRESSAUTODETECT=false
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock  
    - CORE_PEER_ID=peer1.org1.example.com
    - CORE_PEER_ADDRESS=peer1.org1.example.com:7061
    - CORE_PEER_LISTENADDRESS=0.0.0.0:7061
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7062
    - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:7062
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:70561
    - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051
    - CORE_PEER_LOCALMSPID=Org1MSP
    - FABRIC_LOGGING_SPEC=INFO
    #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to 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
    - core_CHAINCODE_EXECUTETIMEOUT=300ms
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: peer node start
  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:
      - 7061:7061
      - 7062:7062
      - 7063:7063
  network:
    testwork

peer0.org2.example.com:
  image: hyperledger/fabric-peer:2.0
  container_name: peer0.org2.example.com
  environment:
    #- CORE_PEER_ADDRESSAUTODETECT=false
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock  
    - CORE_PEER_ID=peer0.org2.example.com
    - CORE_PEER_ADDRESS=peer0.org2.example.com:8051
    - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
    - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:8052
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:8061
    - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:8051
    - CORE_PEER_LOCALMSPID=Org2MSP
    - FABRIC_LOGGING_SPEC=INFO
    #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to 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
    - core_CHAINCODE_EXECUTETIMEOUT=300ms
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: peer node start
  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:
      - 8051:8051
      - 8052:8052
      - 8053:8053
  network:
    testwork

peer1.org2.example.com:
  image: hyperledger/fabric-peer:2.0
  container_name: peer1.org2.example.com
  environment:
    #- CORE_PEER_ADDRESSAUTODETECT=false
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock  
    - CORE_PEER_ID=peer1.org2.example.com
    - CORE_PEER_ADDRESS=peer1.org2.example.com:8061
    - CORE_PEER_LISTENADDRESS=0.0.0.0:8061
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8062
    - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:8062
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:8051
    - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:8051
    - CORE_PEER_LOCALMSPID=Org2MSP
    - FABRIC_LOGGING_SPEC=INFO
    #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to 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
    - core_CHAINCODE_EXECUTETIMEOUT=300ms
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: peer node start
  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:
      - 8061:8061
      - 8062:8062
      - 8063:8063
  network:
    testwork

cli1:
  image: hyperledger/fabric-tools:2.0
  stdin_open: true
  container_name: cli
  tty: true
  depends_on:
    - peer0.org1.example.com
    - peer1.org1.example.com
    - peer0.org2.example.com
    - peer1.org2.example.com
  environment:
    - GOPATH=/opt/gopath
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock
    - FABRIC_LOGGING_SPEC=INFO
    - CORE_PEER_ID=cli
    - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # default to operate on peer0.org1
    - CORE_PEER_LOCALMSPID=Org1MSP
    - CORE_PEER_TLS_ENABLED=true  # to enable TLS, change to true
    - 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
  volumes:
    - /var/run/:/host/var/run/
    - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go 
    - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
    - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts    
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: /bin/bash
  network:
    testwork

cli2:
  image: hyperledger/fabric-tools:2.0
  stdin_open: true
  container_name: cli2
  tty: true
  depends_on:
    - peer0.org1.example.com
    - peer1.org1.example.com
    - peer0.org2.example.com
    - peer1.org2.example.com
  environment:
    - GOPATH=/opt/gopath
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock
    - FABRIC_LOGGING_SPEC=INFO
    - CORE_PEER_ID=cli
    - CORE_PEER_ADDRESS=peer1.org1.example.com:7061 # default to operate on peer0.org1
    - CORE_PEER_LOCALMSPID=Org1MSP
    - CORE_PEER_TLS_ENABLED=true  # to enable TLS, change to true
    - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.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/peer1.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/peer1.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
  volumes:
    - /var/run/:/host/var/run/
    - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go 
    - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
    - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts    
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: /bin/bash
  network:
    testwork

cli3:
  image: hyperledger/fabric-tools:2.0
  stdin_open: true
  container_name: cli3
  tty: true
  depends_on:
    - peer0.org1.example.com
    - peer1.org1.example.com
    - peer0.org2.example.com
    - peer1.org2.example.com
  environment:
    - GOPATH=/opt/gopath
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock
    - FABRIC_LOGGING_SPEC=INFO
    - CORE_PEER_ID=cli
    - CORE_PEER_ADDRESS=peer0.org2.example.com:8051 # default to operate on peer0.org1
    - CORE_PEER_LOCALMSPID=Org2MSP
    - CORE_PEER_TLS_ENABLED=true  # to enable TLS, change to true
    - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
    - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
    - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
  volumes:
    - /var/run/:/host/var/run/
    - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go 
    - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
    - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts    
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: /bin/bash
  network:
    testwork

cli14:
  image: hyperledger/fabric-tools:2.0
  stdin_open: true
  container_name: cli4
  tty: true
  depends_on:
    - peer0.org1.example.com
    - peer1.org1.example.com
    - peer0.org2.example.com
    - peer1.org2.example.com
  environment:
    - GOPATH=/opt/gopath
    - CORE_VM_ENDPOINT=unix///host/var/docker.sock
    - FABRIC_LOGGING_SPEC=INFO
    - CORE_PEER_ID=cli4
    - CORE_PEER_ADDRESS=peer1.org2.example.com:8061 # default to operate on peer0.org1
    - CORE_PEER_LOCALMSPID=Org2MSP
    - CORE_PEER_TLS_ENABLED=true  # to enable TLS, change to true
    - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.crt
    - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.key
    - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt
    - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
  volumes:
    - /var/run/:/host/var/run/
    - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go 
    - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
    - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts    
  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  command: /bin/bash
  network:
    testwork

https://www.bilibili.com/video/BV1H8411Y74S/?spm_id_from=333.788&vd_source=de1585eb7b5cc18db8bc86435eb81c0f
https://my.oschina.net/j4love/blog/5454098

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段命令的作用是: 1. 执行 `source /etc/profile` 命令,使得之前添加的 Go 语言环境变量生效; 2. 执行 `mkdir -p /home/ubuntu/gopath/src/github.com/hyperledger` 命令,创建一个目录用于存放 Hyperledger Fabric 的源代码; 3. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 代码存放的目录; 4. 执行 `cp /resource/docker-compose /usr/local/bin` 命令,将预设好的 `docker-compose` 文件拷贝到 `/usr/local/bin` 目录下; 5. 执行 `chmod +x /usr/local/bin/docker-compose` 命令,添加可执行权限; 6. 执行 `cp /resource/fabric-samples.tar.gz /home/ubuntu/gopath/src/github.com/hyperledger` 命令,将预设好的 Hyperledger Fabric 样例程序压缩包拷贝到 `github.com/hyperledger` 目录下; 7. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 样例程序所在的目录; 8. 执行 `tar -xf ./fabric-samples.tar.gz` 命令,解压 Hyperledger Fabric 样例程序压缩包; 9. 执行 `source /etc/profile` 命令,重新加载 Go 语言环境变量; 10. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/scripts` 命令,切换到 Hyperledger Fabric 样例程序的脚本目录; 11. 执行 `./bootstrap.sh 1.4.0 1.4.0 0.4.14` 命令,安装 Hyperledger Fabric 所需的依赖组件; 12. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/first-network` 命令,切换到 Hyperledger Fabric 样例程序的第一个网络目录; 13. 执行 `./byfn.sh up -s couchdb` 命令,启动第一个网络,并使用 CouchDB 作为状态数据库; 14. 执行 `docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml -f docker-compose-kafka.yaml start` 命令,启动 Fabric 网络中的 Docker 容器; 15. 执行 `../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx channel-artifacts/test.tx -channelID test` 命令,使用 configtxgen 工具生成通道交易配置文件和创世块配置文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值