docker构建镜像报错:
[root@sanxingtongxue ~]# docker build -t hello:v1 .
Sending build context to Docker daemon 28.76MB
Step 1/7 : FROM ubuntu:22.04
---> df5de72bdb3b
Step 2/7 : RUN apt-get update && apt-get install -y python3 python3-pip
---> Running in d528d878d065
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Err:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3
E: Unable to locate package python3-pip
The command '/bin/sh -c apt-get update && apt-get install -y python3 python3-pip' returned a non-zero code: 100
报错内容是找不到python的包,初步判定是docker从官网下载,网速太慢导致。
配置加速器:
中国官方镜像加速:
https://registry.docker-cn.com
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
配置完后,构建成功:
[root@sanxingtongxue ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello v1 e3373de0f59b 18 seconds ago 465MB
使用 Docker需要从官方获取镜像,但由于的网络原因拉取镜像的过程非常耗时。因此 DaoCloud 推出了加速器解决这个难题,通过智能路由和缓存机制,极大提升了国内网络访问 Docker Hub 的速度。
Docker 1.8 或更高版本才能使用。
Docker 官方和国内很多云服务商都提供了国内加速器服务,例如:
科大镜像:https://docker.mirrors.ustc.edu.cn/
网易:https://hub-mirror.c.163.com/
阿里云:https://<你的ID>.mirror.aliyuncs.com
七牛云加速器:https://reg-mirror.qiniu.com
阿里云镜像获取地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
查看是否与你配置的地址一致。
[root@sanxingtongxue ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
...
Registry Mirrors:
‘’https://registry.docker-cn.com/
一点浩然气,千里快哉风。