• Docker报错:E: Unable to locate package python3


    报错

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    解决

    报错内容是找不到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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    配置完后,构建成功:

    [root@sanxingtongxue ~]# docker images 
    REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
    hello        v1        e3373de0f59b   18 seconds ago   465MB
    
    • 1
    • 2
    • 3

    扩展

    镜像加速器是什么

    使用 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/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述
    一点浩然气,千里快哉风。

  • 相关阅读:
    Unity3d-异步加载场景、进度条加载
    VulnHub metasploitable-1
    Sybase连接详解
    springboot基于BS结构的企业人事管理系统的设计与实现毕业设计源码121727
    如何使用 Python 中 Pandas 进行数据分析?
    MySQL 锁
    一文带你了解 Spring 的@Enablexxx 注解
    径向基函数拟合
    前端请求patch接口,只传入已修改字段值的字段
    vue v-model
  • 原文地址:https://blog.csdn.net/qq_35764295/article/details/126222367