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

13,930

Solution 1

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.

Solution 2

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
Share:
13,930

Related videos on Youtube

Richard
Author by

Richard

Updated on September 18, 2022

Comments

  • Richard
    Richard over 1 year

    Running docker build . against the following dockerfile

    FROM ubuntu:16.04
    MAINTAINER [email protected]
    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 [email protected]
    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?

    • FatalMerlin
      FatalMerlin over 7 years
      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.
    • Richard
      Richard over 7 years
      Neither --no-cache nor deleting all my images makes a difference to the error
    • FatalMerlin
      FatalMerlin over 7 years
      Try updating/upgrading docker, this occurred mid 2016 and was already fixed.
    • Richard
      Richard over 7 years
      I'm on Docker 1.12.6 (the latest version from January 2017)
    • FatalMerlin
      FatalMerlin over 7 years
      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 :)
    • Richard
      Richard over 7 years
      No (I installed using curl getdocker.com). I'm on an Ubuntu VM. Fibre internet connection. Don't think I have a proxy, wouldn't know how to check. The build command & dockerfile is in the question. Thanks for your help.
  • Richard
    Richard over 7 years
    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...
  • FatalMerlin
    FatalMerlin over 7 years
    Sadly I don't know how to install them... You should ask the Docker Community for help! :)