title: 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?
body: <p>My team uses Docker (with <code>ubuntu:14.04</code> base image) for local development and we often have to rebuild some or all of our images. But we often get failures downloading packages with <code>apt-get install</code>, even immediately after running <code>apt-get -y update</code>. For instance, today I see</p>
  
  <pre><code>Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libxml2 amd64 2.9.1+dfsg1-3ubuntu4.7
    404  Not Found [IP: 91.189.88.161 80]
  Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libxml2-dev amd64 2.9.1+dfsg1-3ubuntu4.7
    404  Not Found [IP: 91.189.88.161 80]
  Fetched 84.7 MB in 1min 6s (1281 kB/s)
  Unable to correct missing packages.
  E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2_2.9.1+dfsg1-3ubuntu4.7_amd64.deb  404  Not Found [IP: 91.189.88.161 80]
  
  E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2-dev_2.9.1+dfsg1-3ubuntu4.7_amd64.deb  404  Not Found [IP: 91.189.88.161 80]
  
  E: Aborting install.
  </code></pre>
  
  <p>Apparently the specific version of a particular package has been deleted from the archive and replaced with a slightly differently named patch version. For instance, the above error is looking for <code>libxml2_2.9.1+dfsg1-3ubuntu4.7_amd64.deb</code> but the version on the server is <code>libxml2_2.9.1+dfsg1-3ubuntu4.8_amd64.deb</code>.</p>
  
  <p>Often this is solvable by removing the base image (<code>docker rmi ubuntu:14.04</code>) and rebuilding; the newly downloaded ubuntu image has the correct patch number and finds the right archive file. But even this doesn't always work -- probably due to a delay between a new minor upgrade to Ubuntu's dependency db and the deployment of that new <code>ubuntu:14.04</code> image onto Docker Hub.</p>
  
  <p>We've tried using <code>apt-get</code> flags <code>--fix-missing</code> and <code>--fix-broken</code> and those don't consistently work either.</p>
  
  <p>Any other ideas?</p>
  
  <p><a href="https://stackoverflow.com/questions/34778262/apt-get-install-fails-with-not-found-error-because-package-removed-from-reposito">apt-get install fails with Not Found error because package removed from repository</a> is a similar problem but the accepted answer is unacceptable because it's not possible to be automated. Our daily development process, including automatic build and deploy, is all scripted and using Docker and it's not practical to hack around inside a Dockerfile every time a particular archive goes missing (then remove the hack after a few hours or days).</p>
  
  <hr>
  
  <p>In response to @prateek05, here's the <code>/etc/apt/sources.list</code> from the official <code>ubuntu:14.04</code> docker image:</p>
  
  <pre><code>root@72daa1942714:/# cat /etc/apt/sources.list
  # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
  # newer versions of the distribution.
  
  deb http://archive.ubuntu.com/ubuntu/ trusty main restricted
  deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted
  
  ## Major bug fix updates produced after the final release of the
  ## distribution.
  deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted
  deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted
  
  ## Uncomment the following two lines to add software from the 'universe'
  ## repository.
  ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  ## team. Also, please note that software in universe WILL NOT receive any
  ## review or updates from the Ubuntu security team.
  deb http://archive.ubuntu.com/ubuntu/ trusty universe
  deb-src http://archive.ubuntu.com/ubuntu/ trusty universe
  deb http://archive.ubuntu.com/ubuntu/ trusty-updates universe
  deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates universe
  
  ## N.B. software from this repository may not have been tested as
  ## extensively as that contained in the main release, although it includes
  ## newer versions of some applications which may provide useful features.
  ## Also, please note that software in backports WILL NOT receive any review
  ## or updates from the Ubuntu security team.
  # deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted
  # deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted
  
  deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted
  deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted
  deb http://archive.ubuntu.com/ubuntu/ trusty-security universe
  deb-src http://archive.ubuntu.com/ubuntu/ trusty-security universe
  # deb http://archive.ubuntu.com/ubuntu/ trusty-security multiverse
  # deb-src http://archive.ubuntu.com/ubuntu/ trusty-security multiverse
  </code></pre>