标签:指定 rest oca 为我 env container app root sea
环境:ubuntu 16.04
Docker 17.04.0-ce
go 1.7.4
consoul v0.8.0.4
=======================================================================
一、项目准备
想必能搜到这篇文章的人对Hyperledger Fabric(以下简称Fabric)已经是有了一定的了解了,我就不多介绍了。
先说一下Fabric的构建环境:
Hyperledger Fabric tag v1.0.0-alpha (Fabric 的主项目)
Hyperledger Fabric-sdk-node branch v1.0.0-alpha(Fabric的js应用的sdk)
Hyperledger Fabric-ca branch v1.0.0-alpha(Fabric的权限管理项目)
两台主机,处于同一个网段。
这里要多说两句,我们从git hub 服务器(无论是github.com还自己搭建的服务器)上clone下来的工程一般默认是在master分支上的,所以我们下载下来上面三个工程后要记得切换分支,目前在我写这篇博文的时候已经是Fabric1.0已经推出三个版本了(alpha、alpha2、beta),我们用的是第一个发行版本v1.0.0-alpha。
说一下切换分支的方法,熟悉的人可以跳过:
第一种在克隆的时候指定分支
git clone --branch <远程分支名> <源地址>
第二种是克隆后切换分支
git clone <源地址>
git checkout <远程分支名> #此时你的git仓库头指针是游离的,需要新建一个本地分支和远程绑定
git checkout -b <本地分支名> #绑定完成
ps:切换分支之前请保证本地的文件已经完全提交且与远程一致,否则会报错。
二、镜像获取
镜像的获取方式有很多种,不一定非要自己从源代码编译,你也可以从官网指定的地址去拉去镜像,或者直接执行 `docker pull` 命令。
如果想用源码编译镜像的话很简单,分别切换到$fabric、$fabric-ca下执行 ` make docker `
ps:这里友情提示以下,从源码编译最好是准备一个梯子,否则你会痛苦不堪,推荐直接拉取编译好的镜像。
参考地址:
三、环境搭建
现在开始讲最重要的部分,所有服务基于docker多机环境搭建绕不开一个问题:跨主机通信的。根据我在网上搜集来的信息可以将实现跨主机通讯的方法分为以下几种:
1> 本地共享:最直接的方式就是与主机共享网络资源,这种方式的弊端也很明显。
2> 物理桥接:将物理网卡桥接到docker的所依赖的虚拟网桥中,将ip地址限定为物理主机同一网段,这个方式跟1差不多。
3> swarm(docker或第三 提供的docker集成管理项目):简单来说就是将多主机纳入同一个docker manager下,将底层的资源调度分配与客户端部署隔离,主要是构建docker集群。Fabric社区中有一个kubernetes的讨论组,他们现在主要研究方向就是将云服务器与kubernetes相结合,部署一个“云区块链”,方便那些中小企业部署区块链方案,但是我个人认为这已经是跑偏了。区块链本身是一个去中心化的技术,如果完全托管到云上,岂不是一种变相的中心化?毕竟你所有的数据都在云服务商手中。
4>overlay network: swarm 中也应用到了overlay network 基于的是vxlan技术,就是在主机网络上在封装一层虚拟网络,达到将所有容器纳入同一网段的目的。而且它相比于直接的物理桥接有一个好处就是可以根据容器的host name来动态解析路由容器的ip,只要你容器host name不变,我们之间就能互联,从而实现了ip的动态分配。
其实用第三种方法更方便一些,因为我们要执行docker-compose.yml来部署环境,而在swarm二中可以通过 ‘docker stack deploy -c <compose>.yml <name>‘来一键完成傻瓜式部署,但是它有一个弊端,容器的到底部署在哪个节点是根据其调度算法来分配的,我们则是想要指定每一个节点安装的主机。
参考网址:http://www.sdnlab.com/7241.html
综上所述,我们最后采用了 docker-compose + overlay network 的方式来实现我们想要的分布式部署,我们先看一下 $fabric-sdk-node/test/fixtures目录下的 docker-compose.yaml
version: ‘3‘ services: ca0: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org1 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk ports: - "7054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk -b admin:adminpw -d‘ volumes: - ./channel/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_peerOrg1 ca1: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org2 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/464d550fe9bf9e7d8976cdf59d1a5d472598f54c058c3546317c5c5fb0ddfd6e_sk ports: - "8054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/464d550fe9bf9e7d8976cdf59d1a5d472598f54c058c3546317c5c5fb0ddfd6e_sk -b admin:adminpw -d‘ volumes: - ./channel/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_peerOrg2 orderer.example.com: container_name: orderer.example.com image: hyperledger/fabric-orderer environment: - ORDERER_GENERAL_LOGLEVEL=debug - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/twoorgs.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/msp/orderer/keystore/e8a4fdaacf1ef1d925686f19f56eb558b6c71f0116d85916299fc1368de2d58a_sk - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/msp/orderer/signcerts/orderer.example.com-cert.pem - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/msp/orderer/cacerts/example.com-cert.pem, /etc/hyperledger/msp/peerOrg1/cacerts/org1.example.com-cert.pem, /etc/hyperledger/msp/peerOrg2/cacerts/org2.example.com-cert.pem] working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer command: orderer ports: - 7050:7050 dns: - 8.8.8.8 - 8.8.4.4 volumes: - ./channel:/etc/hyperledger/configtx - ./channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peerOrg1 - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/msp/peerOrg2 peer0.org1.example.com: container_name: peer0.org1.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_PEER_ID=peer0.org1.example.com - CORE_LOGGING_PEER=debug - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/ - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/msp/peer/keystore/ecd9f80eb183352d5d4176eeb692e30bbfba4c38813ff9a0b6b799b546dda1d8_sk - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/msp/peer/signcerts/peer0.org1.example.com-cert.pem - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/msp/peer/cacerts/org1.example.com-cert.pem # # 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=fixtures_default - GOPATH=/tmp/gopath working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: peer node start --peer-defaultchain=false ports: - 7051:7051 - 7053:7053 volumes: - ./src/github.com:/tmp/gopath/src/github.com - /var/run/:/host/var/run/ - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peer depends_on: - orderer.example.com peer0.org2.example.com: container_name: peer0.org2.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_PEER_ID=peer0.org2.example.com - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/ - CORE_PEER_ADDRESS=peer0.org2.example.com:7051 - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/msp/peer/keystore/81c71fd393054571c8d789f302a10390e0e83eb079b02a26a162ee26f02ff796_sk - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/msp/peer/signcerts/peer0.org2.example.com-cert.pem - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/msp/peer/cacerts/org2.example.com-cert.pem # # 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=fixtures_default - GOPATH=/tmp/gopath working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: peer node start --peer-defaultchain=false ports: - 8051:7051 - 8053:7053 volumes: - ./src/github.com:/tmp/gopath/src/github.com - /var/run/:/host/var/run/ - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/msp/peer depends_on: - orderer.example.com couchdb: container_name: couchdb image: hyperledger/fabric-couchdb ports: - 5984:5984 environment: DB_URL: http://localhost:5984/member_db
它所部署Fabric 网络是一个单orderer的solo网络,结构如下:
OrdererMsp |----- orderer.example.com (共识服务节点) Org1MSP |-----peer0.org1.example.com (peer节点、Anchor节点) |-----ca0(ca服务) Org2MSP |-----peer0.org2.example.com |-----ca1 DB |---- couchdb(总帐存储)
为了能分布式部署其中有一些环境变量参数是需要我们进行修改的,至于怎么修改我们等下再说,先说一下构建overlay网络环境,我主要参考了Tony大神的一篇博客,只是因为环境不同有一些改动。
参考网址: http://tonybai.com/2016/02/15/understanding-docker-multi-host-networking/
考虑到kv store在本文并非关键,仅作跨多主机容器网络创建启动的前提条件之用,因此仅用包含一个server节点的”cluster”。
参照拓扑图,我们在上启动一个consul,关于consul集群以及服务注册、服务发现等细节可以参考我之前的一 篇文章:
$consul agent -server -bootstrap-expect 1 -data-dir ./data -node=master -bind=10.10.126.101 -client=0.0.0.0 &
ps :这个consul解压出来之后就是一个二进制的执行文件,我们可以直接把它添加到$PATH路径下面
前面提到过,通过Docker 1.9创建跨多主机容器网络需要重新配置每个主机节点上的Docker Daemon的启动参数:
ubuntu系统这个配置在/lib/systemd/system/docker.service 下: ExecStart=/usr/bin/dockerd -H fd://
修改为ExecStart=/usr/bin/dockerd -H fd:// --dns 8.8.8.8 --dns 8.8.4.4 -H tcp://0.0.0.0:2375 --cluster-advertise <物理网卡的名字,不一定是eth0>:2375 --cluster-store consul://10.10.126.101:8500/network --storage-driver=devicemapper
ps:注意有可能启动服务时候会失败,不要慌。这是因为我们平时默认--storage-driver使用的是aufs模式,当切换到devicemapper模式时可能会发生错误。
code bash:
sudo /usr/bin/dockerd --storage-driver=devicemapper #这时会显示错误的具体信息,其中大概的意思是不能rename一个文件,我们就假设它为 xxx
sudo apt-get install dmsteup
sudo dmsteup rm xxx #执行这个命令之前一定要备份镜像,因为这个命令执行完之后你会发现之前的镜像都不见了
这里多说几句:
-H(或–host)配置的是Docker client(包括本地和远程的client)与Docker Daemon的通信媒介,也是Docker REST api的服务端口。默认是/var/run/docker.sock(仅用于本地),当然也可以通过tcp协议通信以方便远程Client访问,就像上面 配置的那样。非加密网通信采用2375端口,而TLS加密连接则用2376端口。这两个端口已经申请在IANA注册并获批,变成了知名端口。-H可以配置多个,就像上面配置的那样。 unix socket便于本地docker client访问本地docker daemon;tcp端口则用于远程client访问。这样一来:docker pull ubuntu,走docker.sock;而docker -H 10.10.126.101:2375 pull ubuntu则走tcp socket。
–cluster-advertise 配置的是本Docker Daemon实例在cluster中的地址;
–cluster-store配置的是Cluster的分布式KV store的访问地址;
如果你之前手工修改过iptables的规则,建议重启Docker Daemon之前清理一下iptables规则:sudo iptables -t nat -F, sudo iptables -t filter -F等。
ps:为了图方便我直接把防火墙关了,另外我有一篇博客也说过直接修改/etc/default/docker
不会生效。
以10.10.126.101为例:
$ sudo service docker start
$ ps -ef|grep docker
root 2069 1 0 Feb02 ? 00:01:41 /usr/bin/docker -d --dns 8.8.8.8 --dns 8.8.4.4 --storage-driver=devicemapper -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-advertise eth0:2375 --cluster-store consul://10.10.126.101:8500/network
启动后iptables的nat, filter规则与单机Docker网络初始情况并无二致。
101节点上初始网络driver类型:
$docker network ls
NETWORK ID NAME DRIVER
47e57d6fdfe8 bridge bridge
7c5715710e34 none null
19cc2d0d76f7 host host
在101节点上,创建net1:
$ sudo docker network create -d overlay net1
在71节点上,创建net2:
$ sudo docker network create -d overlay net2
之后无论在71节点还是101节点,我们查看当前网络以及驱动类型都是如下结果:
$ docker network ls
NETWORK ID NAME DRIVER
283b96845cbe net2 overlay
da3d1b5fcb8e net1 overlay
00733ecf5065 bridge bridge
71f3634bf562 none null
7ff8b1007c09 host host
此时,iptables规则也并无变化。
我们分别在net1和net2下面启动两个container,每个节点上各种net1和net2的container各一个:
101:
sudo docker run -itd --name net1c1 --net net1 ubuntu:14.04
sudo docker run -itd --name net2c1 --net net2 ubuntu:14.04
71:
sudo docker run -itd --name net1c2 --net net1 ubuntu:14.04
sudo docker run -itd --name net2c2 --net net2 ubuntu:14.04
启动后,我们就得到如下网络信息(容器的ip地址可能与前面拓扑图中的不一致,每次容器启动ip地址都可能变化):
net1:
net1c1 - 10.0.0.7
net1c2 - 10.0.0.5
net2:
net2c1 - 10.0.0.4
net2c2 - 10.0.0.6
在net1c1中,我们来看看其到net1和net2的连通性:
root@021f14bf3924:/# ping net1c2
PING 10.0.0.5 (10.0.0.5) 56(84) bytes of data.
64 bytes from 10.0.0.5: icmp_seq=1 ttl=64 time=0.670 ms
64 bytes from 10.0.0.5: icmp_seq=2 ttl=64 time=0.387 ms
^C
--- 10.0.0.5 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.387/0.528/0.670/0.143 ms
root@021f14bf3924:/# ping 10.0.0.4
PING 10.0.0.4 (10.0.0.4) 56(84) bytes of data.
^C
--- 10.0.0.4 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms
可见,net1中的容器是互通的,但net1和net2这两个overlay net之间是隔离的。
ps:这就是我们前面说的,overlay网络同网段下运行容器可以根据容器的host name 路由到目的容器.
如果你一路执行到这里说明你的overlay环境已经搭好了,那么我们说一下docker-compose.yaml应该如何修改:
1>将Fabric拆分为两个部分:
host1 (104)包含order、Org1、couchdb
host2 (121) 包含Org2
所以我将docker-compose.yaml也拆成了两个部分。
2>网络的设定:
我们之前会新建两个overlay网络net1、net2,为了省事我们就直接用net1作为指定的网络。如果我们不指定网络,docker-compose会默认生成一个brige网络<($dirname)_default>,这样是无法联通的。
3>参数修改:
CORE_VM_ENDPOINT= tcp://ip:port
fabric目前没有运行chain code 的虚拟机,当部署chain code时它会自动构建一个docker镜像,然后再以运行容器的方式来执行chain code。这个环境变量的作用救是在部署chain code时候,指定peer与docker后台服务通信地址.
CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=net1
指定peer的network
4>示例
host(104) :docer-compose-0.yaml
version: ‘3‘ services: ca0: container_name: ca_peerOrg1 image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org1 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk ports: - "7054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk -b admin:adminpw -d‘ volumes: - ./channel/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config networks: - net1 orderer.example.com: container_name: orderer.example.com image: hyperledger/fabric-orderer environment: - ORDERER_GENERAL_LOGLEVEL=debug - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/twoorgs.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/msp/orderer/keystore/e8a4fdaacf1ef1d925686f19f56eb558b6c71f0116d85916299fc1368de2d58a_sk - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/msp/orderer/signcerts/orderer.example.com-cert.pem - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/msp/orderer/cacerts/example.com-cert.pem, /etc/hyperledger/msp/peerOrg1/cacerts/org1.example.com-cert.pem, /etc/hyperledger/msp/peerOrg2/cacerts/org2.example.com-cert.pem] working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer command: orderer ports: - 7050:7050 volumes: - ./channel:/etc/hyperledger/configtx - ./channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peerOrg1 - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/msp/peerOrg2 networks: - net1 peer0.org1.example.com: container_name: peer0.org1.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT=tcp://192.168.1.104:2375 - CORE_PEER_ID=peer0.org1.example.com - CORE_LOGGING_PEER=debug - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/ - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/msp/peer/keystore/ecd9f80eb183352d5d4176eeb692e30bbfba4c38813ff9a0b6b799b546dda1d8_sk - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/msp/peer/signcerts/peer0.org1.example.com-cert.pem - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/msp/peer/cacerts/org1.example.com-cert.pem # # 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=net1 working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: peer node start --peer-defaultchain=false ports: - 7051:7051 - 7053:7053 volumes: - /var/run/:/host/var/run/ - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peer depends_on: - orderer.example.com networks: - net1 couchdb: container_name: couchdb image: hyperledger/fabric-couchdb ports: - 5984:5984 environment: DB_URL: http://localhost:5984/member_db networks: - net1 networks: net1: external: true #此网络由外部引用,无需创建
host(121) docker-compose-1.yaml
version: ‘3‘ services: ca1: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org2 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/464d550fe9bf9e7d8976cdf59d1a5d472598f54c058c3546317c5c5fb0ddfd6e_sk ports: - "7054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/464d550fe9bf9e7d8976cdf59d1a5d472598f54c058c3546317c5c5fb0ddfd6e_sk -b admin:adminpw -d‘ volumes: - ./channel/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_peerOrg2 networks: - net1 peer0.org2.example.com: container_name: peer0.org2.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT=tcp://192.168.1.104:2375 - CORE_PEER_ID=peer0.org2.example.com - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/ - CORE_PEER_ADDRESS=peer0.org2.example.com:7051 - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/msp/peer/keystore/81c71fd393054571c8d789f302a10390e0e83eb079b02a26a162ee26f02ff796_sk - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/msp/peer/signcerts/peer0.org2.example.com-cert.pem - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/msp/peer/cacerts/org2.example.com-cert.pem # # 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=net1 - GOPATH=/tmp/gopath working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: peer node start --peer-defaultchain=false ports: - 7051:7051 - 7053:7053 volumes: - ./src/github.com:/tmp/gopath/src/github.com - /var/run/:/host/var/run/ - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/msp/peer - ./channel:/etc/hyperledger/configtx networks: - net1 networks: net1: external: true
运行的时候先运行docker-compose-0.yaml:
docker-compose -f docer-compose-0.yaml up --force-recreate
然后在另一台主机运行docker-compose-1.yaml
docker-compose -f docer-compose-1.yaml up --force-recreate
运行后执行docker命令进入容器的bash界面
docker exec -it <container> bash
ping 另一个主机上的容器验证是否联通,fabric的镜像里面是没有ping的 我们需要自己手动安装
apt-get update
apt-get install inetutils-ping
如果ping通了那么恭喜你,你已经完成了一半工程了。
基于docker的 Hyperledger Fabric 多机环境搭建(上)
标签:指定 rest oca 为我 env container app root sea
原文地址:http://www.cnblogs.com/cnblogs-wangzhipeng/p/6994541.html