351-fabric浅析docker-compose









fabric浅析docker-compose






我们要启动peer,orderer和客户端
先要配置docker-compose

那么我们先来看下官方的docker-compose
我们打开/fabric-samples/first-network

然后看下目录
abc@abc:~/workspace/fabric/sample/fabric-samples/first-network$ ls
base                     docker-compose-couch-org3.yaml    eyfn.sh
byfn.sh                  docker-compose-couch.yaml         org3-artifacts
channel-artifacts        docker-compose-e2e-template.yaml  README.md
configtx.yaml            docker-compose-etcdraft2.yaml     scripts
crypto-config.yaml       docker-compose-kafka.yaml
docker-compose-cli.yaml  docker-compose-org3.yaml




我们找到docker-compose-cli.yaml
我们把docker-compose-cli.yaml复制一下






然后我们来看一下
docker-compose-cli.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:
    extends:
      file:   base/docker-compose-base.yaml
      service: 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:
    container_name: cli
    image: hyperledger/fabric-tools:$IMAGE_TAG
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- FABRIC_LOGGING_SPEC=DEBUG
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=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/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/chaincode
        - ./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:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn







我们发现有用到base文件夹
那么我们去first-network文件夹把base文件夹也拷贝过来

abc@abc:~/workspace/fabric$ ls
abc.yaml  channel.tx     crypto-config            genesis.block  template.yaml
base      configtx.yaml  docker-compose-cli.yaml  sample









我们来看一下docker-compose里面的cli

  cli:
    container_name: cli
    image: hyperledger/fabric-tools:$IMAGE_TAG
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- FABRIC_LOGGING_SPEC=DEBUG
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=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/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/chaincode
        - ./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:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn





看下里面有什么
1.container_name 	容器名字
2.image				镜像
3.tty				true,有终端绑定
4.stdin_open		true,标准输入为打开状态
5.environment		环境变量
6.working_dir		工作目录
7.command			执行bash命令
8.volumes			数据卷挂载
9.depends_on		
10.networks			












我们来看下镜像
docker images

hyperledger/fabric-tools           1.2.1               7aea1cc899d1        6 months ago        1.51GB
hyperledger/fabric-tools           latest              7aea1cc899d1        6 months ago        1.51GB
hyperledger/fabric-ccenv           1.2.1               8651e7160d88        6 months ago        1.43GB
hyperledger/fabric-ccenv           latest              8651e7160d88        6 months ago        1.43GB
hyperledger/fabric-orderer         1.2.1               b1a1dd788841        6 months ago        152MB
hyperledger/fabric-orderer         latest              b1a1dd788841        6 months ago        152MB
hyperledger/fabric-peer            1.2.1               ef0e7788ead0        6 months ago        159MB
hyperledger/fabric-peer            latest              ef0e7788ead0        6 months ago        159MB
hyperledger/fabric-ca              1.2.1               be8400395e15        6 months ago        251MB
hyperledger/fabric-ca              latest              be8400395e15        6 months ago        251MB
hyperledger/fabric-zookeeper       0.4.10              2b51158f3898        9 months ago        1.44GB
hyperledger/fabric-zookeeper       latest              2b51158f3898        9 months ago        1.44GB
hyperledger/fabric-kafka           0.4.10              936aef6db0e6        9 months ago        1.45GB
hyperledger/fabric-kafka           latest              936aef6db0e6        9 months ago        1.45GB
hyperledger/fabric-couchdb         0.4.10              3092eca241fc        9 months ago        1.61GB
hyperledger/fabric-couchdb         latest              3092eca241fc        9 months ago        1.61GB
hyperledger/fabric-baseos          amd64-0.4.10        52190e831002        9 months ago        132MB










我们来看一下环境变量

    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- FABRIC_LOGGING_SPEC=DEBUG
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=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/[email protected]/msp
  



1.GOPATH						#go根路径
2.CORE_VM_ENDPOINT				#固定值
3.FABRIC_LOGGING_SPEC			#日志级别
4.CORE_PEER_ID					#节点ID
5.CORE_PEER_ADDRESS				#节点地址
6.CORE_PEER_LOCALMSPID			#组织ID
7.CORE_PEER_TLS_ENABLED			#是否对数据加密
8.CORE_PEER_TLS_CERT_FILE		#TLS证书
9.CORE_PEER_TLS_KEY_FILE		#TLS私钥
10.CORE_PEER_TLS_ROOTCERT_FILE 	#TLS根证书
11.CORE_PEER_MSPCONFIGPATH		#MSP目录











leader节点
1.peer节点
2.代表组织和orderer节点通信
3.在一个组织中,leader节点只有一个
4.谁都有资格做leader节点
5.如何指定
	1.手动指定,如果指定leader挂了,就没有leader节点了
	2.自动选举,当前的leader节点挂了,还是会再选一个

- CORE_PEER_GOSSIP_USELEADERELECTION=true 	#是否自动选举
- CORE_PEER_GOSSIP_ORGLEADER=false			#是否指定当前节点为leader
















 

你可能感兴趣的:(fabric)