Docker build ubuntu 无法执行 apt-get update - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
LieNoWell
V2EX    Docker

Docker build ubuntu 无法执行 apt-get update

  •  
  •   LieNoWell 2019-06-20 17:08:23 +08:00 9045 次点击
    这是一个创建于 2380 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这是一个老问题了,但确实没找到原因。

    Dockerfile 内容:

    FROM ubuntu:xenial RUN apt-get update && apt-get upgrade -y RUN apt-get install -y net-tools CMD ifconfig 

    build 时报错:

    Step 1/4 : FROM ubuntu:xenial ---> 13c9f1285025 Step 2/4 : RUN apt-get update && apt-get upgrade -y ---> Running in 7d9b2ce81413 Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease Temporary failure resolving 'security.ubuntu.com' Err:2 http://archive.ubuntu.com/ubuntu xenial InRelease Temporary failure resolving 'archive.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-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... Calculating upgrade... 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ---> 2bbbf2281fbf Removing intermediate container 7d9b2ce81413 Step 3/4 : RUN apt-get install -y net-tools ---> Running in ce96aba3aea8 Reading package lists... Building dependency tree... Reading state information... E: Unable to locate package net-tools The command '/bin/sh -c apt-get install -y net-tools' returned a non-zero code: 100 

    很明显是 apt-get 无法 update

    已经尝试的解决方式:

    1、更改为国内源(阿里源与 163 源,也测试过 sed 直接修改),无效:

    RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \ echo 'deb http://mirrors.163.com/debian/ jessie main non-free contrib' > /etc/apt/sources.list && \ echo 'deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib' >> /etc/apt/sources.list 

    报错原因同之前:

    Err:1 http://mirrors.163.com/debian jessie InRelease Temporary failure resolving 'mirrors.163.com' 

    2、尝试更改 DNS ( 1 )我需要在 docker build 时指定 DNS,不是 run 的时候 ( 2 ) DNS 中已经有 114.114.114.114

    PS:宿主机可以执行 apt-update

    3 条回复    2019-09-23 09:52:59 +08:00
    XSG
        1
    XSG  
       2019-07-01 16:34:23 +08:00
    你的源错了
    看下你 FROM 的镜像是 xenial,但是修改的 apt 源是 jessie,不匹配!
    pacoxu
        2
    pacoxu  
       2019-07-02 13:21:30 +08:00
    https://github.com/pacoxu/dao-tomcat/tree/master/samples

    写了个简单的例子,找了个 ubuntu 的 aliyun 源

    docker build .
    Sending build context to Docker daemon 3.584kB
    Step 1/3 : FROM ubuntu:xenial
    xenial: Pulling from library/ubuntu
    Digest: sha256:a4d8e674ee993e5ec88823391de828a5e9286a1597b731eaecaaf9066cfdf539
    Status: Downloaded newer image for ubuntu:xenial
    ---> 13c9f1285025
    Step 2/3 : COPY sources.list /etc/apt/sources.list
    ---> 93899785ec2a
    Step 3/3 : RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/*
    ---> Running in 2369ec47a573
    Get:1 http://mirrors.aliyun.com/ubuntu xenial InRelease [247 kB]
    Get:2 http://mirrors.aliyun.com/ubuntu xenial-security InRelease [109 kB]
    Get:3 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease [109 kB]
    LieNoWell
        3
    LieNoWell  
    OP
       2019-09-23 09:52:59 +08:00   2
    最后解决的方法是 docker build 指定 --network=host
    问题中已经说明:宿主机中可以 update,容器中不可以,应该是 docker 配置问题

    PS:
    更改源版本不对是复制的代码,实际上是正确的版本
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     913 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 22:28 PVG 06:28 LAX 14:28 JFK 17:28
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86