报错
docker构建镜像报错:
[root@sanxingtongxue ~]# docker build -t hello:v1 .Sending build context to Docker daemon 28.76MBStep 1/7 : FROM ubuntu:22.04---> df5de72bdb3bStep 2/7 : RUN apt-get update && apt-get install -y python3 python3-pip---> Running in d528d878d065Ign:1 /ubuntu jammy-security InReleaseIgn:2 /ubuntu jammy InReleaseIgn:3 /ubuntu jammy-updates InReleaseIgn:1 /ubuntu jammy-security InReleaseIgn:4 /ubuntu jammy-backports InReleaseIgn:1 /ubuntu jammy-security InReleaseIgn:2 /ubuntu jammy InReleaseErr:1 /ubuntu jammy-security InReleaseTemporary failure resolving ''Ign:3 /ubuntu jammy-updates InReleaseIgn:4 /ubuntu jammy-backports InReleaseIgn:2 /ubuntu jammy InReleaseIgn:3 /ubuntu jammy-updates InReleaseIgn:4 /ubuntu jammy-backports InReleaseErr:2 /ubuntu jammy InReleaseTemporary failure resolving ''Err:3 /ubuntu jammy-updates InReleaseTemporary failure resolving ''Err:4 /ubuntu jammy-backports InReleaseTemporary failure resolving ''Reading package lists...W: Failed to fetch /ubuntu/dists/jammy/InRelease Temporary failure resolving ''W: Failed to fetch /ubuntu/dists/jammy-updates/InRelease Temporary failure resolving ''W: Failed to fetch /ubuntu/dists/jammy-backports/InRelease Temporary failure resolving ''W: Failed to fetch /ubuntu/dists/jammy-security/InRelease Temporary failure resolving ''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 python3E: Unable to locate package python3-pipThe 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-
mkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors": ["https://registry.docker-"]}EOFsystemctl daemon-reloadsystemctl restart docker
配置完后,构建成功:
[root@sanxingtongxue ~]# docker images REPOSITORY TAG IMAGE ID CREATEDSIZEhello v1 e3373de0f59b 18 seconds ago 465MB
扩展
镜像加速器是什么
使用 Docker需要从官方获取镜像,但由于的网络原因拉取镜像的过程非常耗时。因此 DaoCloud 推出了加速器解决这个难题,通过智能路由和缓存机制,极大提升了国内网络访问 Docker Hub 的速度。
Docker 1.8 或更高版本才能使用。
加速器地址
Docker 官方和国内很多云服务商都提供了国内加速器服务,例如:
科大镜像:https://docker.mirrors./
网易:https://hub-mirror./
阿里云:https://<你的ID>.
七牛云加速器:https://reg-
阿里云镜像获取地址:https://cr./cn-hangzhou/instances/mirrors
检查加速器配置是否生效
查看是否与你配置的地址一致。
[root@sanxingtongxue ~]# docker infoClient:Context: defaultDebug Mode: falsePlugins:...Registry Mirrors:‘’https://registry.docker-/
一点浩然气,千里快哉风。