Ubuntu20.04下构建Hyperledger Indy-sdk镜像apt-get update超时如何解决
问题解决方法
根因分析
- Ubuntu 16.04(Xenial)已于2021年4月结束标准生命周期,官方软件源
archive.ubuntu.com已经下线了Xenial相关的包索引,访问会出现超时或404错误 - Docker镜像构建阶段默认使用Docker自带的
docker0网桥,若该网桥存在iptables规则限制、MTU不匹配等问题,也会导致容器内网络访问超时
修复步骤
方案1:替换Dockerfile中的Ubuntu源为旧版本源
修改getting-started.dockerfile,在第一个RUN apt-get update之前添加替换源的命令:
FROM ubuntu:16.04 RUN useradd -ms /bin/bash indy # 新增:替换为Ubuntu 16.04旧版本源 RUN sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list RUN sed -i 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list # Install environment RUN apt-get update -y && apt-get install -y \ wget \ python3.5 \ python3-pip \ python-setuptools \ apt-transport-https \ ca-certificates \ software-properties-common # 后续原有内容保持不变
建议同步修改indy-pool.dockerfile的源,避免后续重新构建indy-pool镜像时出现相同问题。
方案2:指定构建阶段使用宿主机网络
镜像构建阶段默认不会使用docker-compose中定义的pool_network,可手动指定构建时使用host网络,直接复用宿主机的网络配置规避Docker网桥问题:
方式A:修改docker-compose.yml的build配置
给jupyter服务的build字段添加network: host配置:
jupyter: build: context: . dockerfile: getting-started.dockerfile network: host # 新增这一行 command: jupyter notebook --ip=0.0.0.0 # 后续原有内容保持不变
修改完成后重新执行docker-compose build即可。
方式B:手动单独构建getting-started镜像
执行以下命令直接用host网络构建镜像:
docker build --network=host -f getting-started.dockerfile -t getting-started .
构建完成后再执行docker-compose up -d启动服务即可。
方案3:修复Docker默认网桥网络
如果上述方案都无效,可重置Docker的网络配置:
# 停止Docker服务 sudo systemctl stop docker # 清空iptables的nat规则 sudo iptables -t nat -F # 重启Docker服务,会自动重建网桥和规则 sudo systemctl start docker
重置完成后重新执行构建命令即可。
内容的提问来源于stack exchange,提问作者manoj
相关产品推荐
相关产品推荐

