In Docker, apt-get install fails with “Failed to fetch http://archive.ubuntu.com/ … 404 Not Found” errors. Why? How can we get past it?

后端 未结 5 884
轻奢々
轻奢々 2020-12-13 05:46

My team uses Docker (with ubuntu:14.04 base image) for local development and we often have to rebuild some or all of our images. But we often get failures downl

相关标签:
5条回答
  • 2020-12-13 06:09

    Using FTP sources works 100% of the time.

    RUN echo \
       'deb ftp://ftp.us.debian.org/debian/ jessie main\n \
        deb ftp://ftp.us.debian.org/debian/ jessie-updates main\n \
        deb http://security.debian.org jessie/updates main\n' \
        > /etc/apt/sources.list
    
    0 讨论(0)
  • 2020-12-13 06:14

    The issue could be potentially with the ubuntu sources

    Check /etc/apt/sources.list

    If you see deb http://archive.ubuntu.com/ubuntu main universe restricted multiverse , that could be the potential issue.

    Fix that by replacing it with deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse

    Alternatively it could be the mirror itself doesn't respond. archive.ubuntu.com

    Name:   archive.ubuntu.com
    Address: 91.189.88.152
    Name:   archive.ubuntu.com
    Address: 91.189.88.161
    Name:   archive.ubuntu.com
    Address: 91.189.88.149
    

    Replace archive.ubuntu.com with a more trusted mirror say us.archive.ubuntu.com

    Name:   us.archive.ubuntu.com
    Address: 91.189.91.23
    Name:   us.archive.ubuntu.com
    Address: 91.189.91.26
    

    (edit by the oiriginal asker):

    Thanks, prateek05! My Dockerfile now starts:

    FROM ubuntu:14.04
    RUN sed -i'' 's/archive\.ubuntu\.com/us\.archive\.ubuntu\.com/' /etc/apt/sources.list
    RUN apt-get -y update
    

    and it seems to be working. But since this is a sporadic issue, only time will tell...

    0 讨论(0)
  • 2020-12-13 06:16

    You have stated that your Dockerfile contains RUN apt-get -y update as its own RUN instruction. However, due to build caching, if all changes to the Dockerfile occur later in the file, when docker build is run, Docker will reuse the intermediate image created the last time RUN apt-get -y update executed instead of running the command again, and so any recently-added or -edited apt-get install lines will be using old data, leading to the errors you've observed.

    There are two ways to fix this:

    1. Pass the --no-cache option to docker build, forcing every statement in the Dockerfile to be run every time the image is built.

    2. Rewrite the Dockerfile to combine the apt-get commands in a single RUN instruction: RUN apt-get update && apt-get install foo bar .... This way, whenever the list of packages to install is edited, docker build will be forced to re-execute the entire RUN instruction and thus rerun apt-get update before installing.

    The Dockerfile best practices page actually has an entire section on apt-get commands in Dockerfiles. I suggest you read it.

    0 讨论(0)
  • 2020-12-13 06:20

    found something that works!

    so i found this: https://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg5682159.html

    The solution is to create a pinning_file with the contents

    # Written by ubuntu-advantage-tools
    Package: *
    Pin: release o=UbuntuESM, n=trusty
    Pin-Priority: never
    

    then add

    COPY pinning_file /etc/apt/preferences.d/ubuntu-esm-infra-trusty
    

    to you Dockerfile before you run the sudo apt-get -y update

    0 讨论(0)
  • 2020-12-13 06:30

    In my case the problem was caused by the parent image since it had not cleared the apt cache properly.

    I solve the problem including cleaning commands before the first apt update ...

    RUN apt clean && \
        rm -rf /var/lib/apt/lists/* && \
        apt update && \
        ...
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题