Running docker build . against the following dockerfile

FROM ubuntu:16.04
MAINTAINER b@example.com
RUN apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get update -y 

I get the error E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/source/by-hash/SHA256/50ccff6c903e98e2e52c1ab6dae4a85d23a84369325fd971c4bfc3752e6a7ede Hash Sum mismatch E: Some index files failed to download. They have been ignored, or old ones used instead.

I then tried adding every solution in this question to my dockerfile: Trouble downloading packages list due to a "Hash sum mismatch" error

FROM ubuntu:16.04
MAINTAINER b@example.com
RUN touch /etc/apt/apt.conf.d/99fixbadproxy \
    && echo "Acquire::http::Pipeline-Depth 0;" >> /etc/apt/apt.conf.d/99fixbadproxy \
    && echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99fixbadproxy \
    && echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99fixbadproxy \
    && apt-get update -o Acquire::CompressionTypes::Order::=gz \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get update -y

but I get the same error.

What else can I do?

  • After changing this you might need to build using docker build -no-cache because such a long RUN command as one layer might not have been invalidated in the cache after your changes. – FatalMerlin Jan 17 '17 at 13:22
  • Neither --no-cache nor deleting all my images makes a difference to the error – Richard Jan 17 '17 at 14:00
  • Try updating/upgrading docker, this occurred mid 2016 and was already fixed. – FatalMerlin Jan 17 '17 at 14:06
  • I'm on Docker 1.12.6 (the latest version from January 2017) – Richard Jan 18 '17 at 5:34
  • did you change anything in your Docker installation? Are you behind a proxy? Is there anything else that might interfere with the internet connection of the container? What command are you using to build? What host are you using Docker on? Please provide more information :) – FatalMerlin Jan 18 '17 at 10:12

I think I might have figured your problem:

You might have missing dependencies for Docker, or docker is not installed correctly.

Here is the full instruction for the Docker installation on Ubuntu.

Especially this part might be missing.

I would advise you to reinstall docker with these official instructions.

If the problem should persist, there might be a problem with the network connection of your VM or your host machine.

After all your Dockerfile seems correct to me, so this shouldn't be the cause.

  • 1
    Thanks! Reviewing all my notes I see at some point my colleagues & I needed specifically to test against Docker 1.12, so I ran sudo apt-get install docker-engine=1.11.2-0~xenial - that must be a bad version. I uninstalled Docker and reinstalled using sudo curl -sSL https://get.docker.com | bash and this Dockerfile works without error. A bit annoying though now, what is the correct way to install an old Docker that doesn't have apt errors... – Richard Jan 19 '17 at 13:33
  • Sadly I don't know how to install them... You should ask the Docker Community for help! :) – FatalMerlin Jan 19 '17 at 15:24

The chosen solution didn't work for me. And I noticed that this isn't always the case - that is, if I wait a day or two, I don't get the error. I suspect it has more to do with the ubuntu repositories than the version of docker we use (as explained by Robie).

My solution is to use one of the official mirrors instead of the default ubuntu repo. Replace xenial with your ubuntu version. You might need an extra deb-src line for all or none of the lines depending on where you are getting the mismatch. I noticed that the mirrors are slower compared to the default.

RUN rm -rf /etc/apt/sources.list
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb-src mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted universe multiverse" >> /etc/apt/sources.list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.