请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

构建镜像不能安装python

[root@localhost code]# docker image build -t hello .
[+] Building 25.9s (7/8) docker:default
=> [internal] load build definition from dockerfile 0.0s
=> => transferring dockerfile: 263B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 2.8s
=> [auth] library/centos:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [1/3] FROM docker.io/library/centos:latest@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6 0.0s
=> ERROR [2/3] RUN yum update -y && yum install -y python39 python39-devel python39-pip && yum clean al 23.1s
=> [internal] load build context 0.0s
=> => transferring context: 89B 0.0s

[2/3] RUN yum update -y && yum install -y python39 python39-devel python39-pip && yum clean all:
22.96 CentOS Linux 8 - AppStream 1.8 B/s | 38 B 00:21
22.97 Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist


dockerfile:2

1 | FROM centos:latest
2 | >>> RUN yum update -y &&
3 | >>> yum install -y python39 python39-devel python39-pip &&
4 | >>> yum clean all
5 | ADD hello.py /

ERROR: failed to solve: process “/bin/sh -c yum update -y && yum install -y python39 python39-devel python39-pip && yum clean all” did not complete successfully: exit code: 1

正在回答 回答被采纳积分+3

1回答

麦兜搞IT 2025-04-24 02:57:11

有可能是CentOS 8 的官方软件源已停止维护,默认的 yum 源可能已经失效,导致无法安装软件包

0 回复 有任何疑惑可以回复我~
  • 可以试试,比如
    
    FROM centos:latest
    
    # 替换为有效的镜像源
    RUN sed -i 's|mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-* \
        && sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
    
    # 更新并安装 Python 3.9
    RUN yum update -y && \
        yum install -y python39 python39-devel python39-pip && \
        yum clean all
    
    ADD hello.py /
    回复 有任何疑惑可以回复我~ 2025-04-24 02:57:23
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号