This series of articles:
Chapter one: nine analyze with you after blasting hyperledger fabric - Quick Start basic-network Sample
Chapter II: nine analyze with you after blasting hyperledger fabric - to quickly build environment GO
Chapter 3: nine analyze with you after blasting hyperledger fabric - Quick Start Sample first-network
Chapter 4: nine analyze with you after blasting hyperledger fabric - system logic architecture articles
Chapter V: nine analyze with you after blasting hyperledger fabirc - Network Node Introduction
Chapter 8: nine analyze with you easily complete explosion hyperledger fabric - Couchdb installation
Chapter 9: nine analyze with you easily complete explosion hyperledger fabric - NVM installation and Nodejs
Chapter 11: nine analyze with you easily complete explosion hyperledger fabric - to create alliances
Chapter XII: nine analyze with you easily complete explosion hyperledger fabric - configtxlator early adopters
Chapter XIII: nine analyze with you easily complete explosion hyperledger fabric - to create static organization
Chapter XIV: Nine analysis with you easily complete explosion WARNING: The COMPOSE_PROJECT_NAME
Chapter XV: nine analyze with you easily complete explosion hyperledger fabric - chaincode chain code calls
Chapter XVI: nine analyze with you easily complete explosion hyperledger fabric - endorsement strategy Polic
Chapter XVII: nine analyze with you easily complete explosion hyperledger fabric - chain code modifications initialization container area
1 Introduction
If you have any questions about the blog, please add micro-channel communication:
2 Problem Description
In the process of migrating to k8s hyperledger fabric container, which is a key step in the initialization chain code operation.
peer chaincode instantiate -o blockchain-orderer:31010 -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -c '{\"Args\":[\"init\",\"a\",\"100\",\"b\",\"200\"]}'
fabric 在 k8s 中初始化链码的整个过程是 client (比如:fabric-tools)向 orderer 发出申请,orderer 将此申请打包发送给 peer 节点,peer 节点会跟宿主机 docker 通信发送创建容器请求,宿主机 docker 收到请求后根据指定镜像运行成链码容器。
这里容易晕眩的点在于,熟悉 k8s 环境的人都知道 k8s 底层容器引擎是 docker,但是使用 k8s 的过程中我们很少直接通过 docker run 去产生容器的,而通常的做法是使用 kubectl 去向 api-server 发送资源管理请求去操作 pod。但是在初始化 fabric 链码的过程中,却是 k8s 中 peer 所在的 pod 直接跟宿主机的 docker 通信,直接利用宿主机 docker 去动态生成链码容器。
由于是动态生成链码容器,所以就不能很随意地的去 mount 宿主机的时区 /etc/localtime。那么解决问题的关键就需要定位动态启动链码时所引用的镜像。可是这个镜像到底是谁呢?
3 问题解决
3.1 编写 Dockerfile 文件
Dockerfile 文件内容如下,我想我不用解释什么了吧:
FROM hyperledger/fabric-baseos:amd64-0.4.18
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
3.2 创建镜像
docker build -t hyperledger/fabric-baseos:amd64-0.4.18 .
4 关注点
Note that this image must be on the node where the peer, if you restart fabric block chain network, peer node drifted does not know on which worker node, so the safe side, you need to mirror this by manually released the following statement on k8s all worker nodes.
docker save -o baseos.tar hyperledger/fabric-baseos:amd64-0.4.18
docker load -i baseos.tar
Since then, nine analyze with you easily modify zone after blasting the chain code to initialize the container.