Fabric镜像拉取
脚本说明
脚本改自官方,可以拉取fabric ca/peer/orderer/ccenv/tools等镜像,我注释掉了拉取第三方镜像(zookeeper,kafka,couchdb)的代码。
脚本内容
创建脚本vi docker_pull_fabric_images.sh。然后复制下面的内容到脚本。
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Fabric 1.4.0 :e.g. bootstrap.sh 1.4.0 1.4.0 0.4.14
# Fabric 1.4.1 :e.g. bootstrap.sh 1.4.1 1.4.1 0.4.15
# if version not passed in, default to latest released version
export VERSION=1.4.1
# if ca version not passed in, default to latest released version
export CA_VERSION=$VERSION
# current version of thirdparty images (couchdb, kafka and zookeeper) released
export THIRDPARTY_IMAGE_VERSION=0.4.15
export MARCH=$(uname -m)
printHelp() {
echo "Usage: docker_pull_fabric_images.sh [<version>] [<ca_version>] [<thirdparty_version>][-d]"
echo
echo "-d - bypass docker image download"
echo
echo "e.g. docker_pull_fabric_images.sh 1.4.0 1.4.0 0.4.14"
echo "would download docker images and binaries for version 1.4.0 (fabric) 1.4.0 (fabric-ca) 0.4.14 (thirdparty)"
}
dockerFabricPull() {
local FABRIC_TAG=$1
for IMAGES in peer orderer ccenv tools; do
echo "==> FABRIC IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
# docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
done
}
dockerThirdPartyImagesPull() {
local THIRDPARTY_TAG=$1
for IMAGES in couchdb kafka zookeeper; do
echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
# docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
done
}
dockerCaPull() {
local CA_TAG=$1
echo "==> FABRIC CA IMAGE"
echo
docker pull hyperledger/fabric-ca:$CA_TAG
# docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}
dockerInstall() {
which docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
echo "===> Pulling fabric Images"
dockerFabricPull ${FABRIC_TAG}
echo "===> Pulling fabric ca Image"
dockerCaPull ${CA_TAG}
# 不拉取三方镜像
# echo "===> Pulling thirdparty docker images"
# dockerThirdPartyImagesPull ${THIRDPARTY_TAG}
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger*
else
echo "========================================================="
echo "Docker not installed, bypassing download of Fabric images"
echo "========================================================="
fi
}
DOCKER=true
SAMPLES=true
# Parse commandline args pull out
# version and/or ca-version strings first
if echo $1 | grep -q '\d'; then
VERSION=$1;shift
if echo $1 | grep -q '\d'; then
CA_VERSION=$1;shift
if echo $1 | grep -q '\d'; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
# prior to 1.1.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0]\.* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
# 从1.2.0版本开始,镜像就使用默认的版本(当前文件中定义的)
: ${FABRIC_TAG:="$VERSION"}
: ${CA_TAG:="$CA_VERSION"}
: ${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}
fi
# then parse opts
while getopts "h?db" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
;;
d) DOCKER=false
;;
esac
done
if [ "$DOCKER" == "true" ]; then
echo
echo "Installing Hyperledger Fabric docker images"
echo
dockerInstall
fi
执行脚本
# 注意:给脚本添加执行权限
# 执行shell可能报错
# 执行.sh脚本时出现$’\r’: 未找到命令
# 是因为脚本在windows下编辑过,windows下的换行带有‘\r’而uninx或者linux下的换行是‘\n’
# 解决办法-->安装dos2unix:
yum install -y dos2unix
# 然后执行命令转换脚本格式:
dos2unix docker_pull_fabric_images.sh.sh
# 脚本赋权
chmod +x docker_pull_fabric_images.sh.sh
# 执行脚本
./docker_pull_fabric_images.sh.sh 1.4.1