fabric 2.0之后的镜像开始使用alphin,有效减少了镜像的大小。
但是在修改代码之后,自己构建docker镜像的时候,默认使用的是下面这个国外地址下载alphin apk
https://dl-cdn.alpinelinux.org
下载速度极慢,通过下面的命令修改成阿里云的更新源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
#使用sed工具将字符串dl-cdn.alpinelinux.org替换为mirrors.aliyun.com
在Dockerfile里面,在安装apk add之前替换更新源即可
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
ARG GO_VER
ARG ALPINE_VER
FROM alpine:${ALPINE_VER} as peer-base
RUN apk add --no-cache tzdata
FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories #新加的
RUN apk add --no-cache \
bash \
gcc \
git \
make \
musl-dev
ADD . $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
FROM golang as peer
ARG GO_TAGS
RUN make peer GO_TAGS=${GO_TAGS}
FROM peer-base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}
EXPOSE 7051
CMD ["peer","node","start"]
如果你用的1.4版本的fabric,apt-get的更新源也是非常慢的,可以这样修改
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean