Ubuntu – How to fix hash sum mismatch error on fresh docker image update

aptdocker

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?

Best Answer

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
Related Question