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?

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.


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...

Tags:

Docker

Ubuntu