How to fix 'Hash Sum Mismatch' in Docker on mac
Asked Answered
K

4

5

I'm using macOS 11.4 and Docker 3.3.3. My docker file looks like

FROM python:3.8.10-slim-buster

RUN apt-get update && apt-get install --no-install-recommends -y \
    # dependencies for building Python packages
    build-essential \
    # psycopg2 dependencies
    libpq-dev

I have tried for different tags of Docker images by Python and have tried to create the image with --no-cache command as well, but every time I try to build image, I get the error Hash Sum mismatch

Here are my logs:

    [+] Building 5.8s (5/5) FINISHED                                                                                                                                                                          
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s
 => => transferring dockerfile: 247B                                                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                                                    0.0s
 => => transferring context: 34B                                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/python:3.8.10-slim-buster                                                                                                                         2.6s
 => CACHED [1/2] FROM docker.io/library/python:3.8.10-slim-buster@sha256:c9dc8cd1171771e7f0def12be61d7bb340480e73b4e78acf3464ed0c3347dabd                                                            0.0s
 => ERROR [2/2] RUN apt-get update && apt-get install --no-install-recommends -y   build-essential   libpq-dev                                                                                       3.1s
------                                                                                                                                                                                                    
 > [2/2] RUN apt-get update && apt-get install --no-install-recommends -y   build-essential   libpq-dev:                                                                                                  
#5 0.751 Get:1 http://deb.debian.org/debian buster InRelease [121 kB]                                                                                                                                     
#5 0.751 Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]                                                                                                              
#5 0.967 Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]                                                                                                                            
#5 1.155 Get:4 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]                                                                                                                          
#5 1.204 Get:5 http://security.debian.org/debian-security buster/updates/main amd64 Packages [290 kB]
#5 2.833 Err:4 http://deb.debian.org/debian buster/main amd64 Packages
#5 2.833   Hash Sum mismatch
#5 2.833   Hashes of expected file:
#5 2.833    - Filesize:7906864 [weak]
#5 2.833    - SHA256:935deda18d5bdc25fb1813d0ec99b6e0e32a084b203e518af0cf7dc79ee8ebda
#5 2.833    - MD5Sum:ba791e511a2a4b6523ac06f404e32f42 [weak]
#5 2.833   Hashes of received file:
#5 2.833    - SHA256:3dbff74a7005b0214ed17ad72a4724cb91919d8d0221b5297f98f6153606bcaa
#5 2.833    - MD5Sum:f24d4da07e9d1e5bccd9d324cb36dd20 [weak]
#5 2.833    - Filesize:7906864 [weak]
#5 2.833   Last modification reported: Sat, 27 Mar 2021 09:33:56 +0000
#5 2.833   Release file created at: Sat, 27 Mar 2021 09:55:13 +0000
#5 3.000 Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [10.9 kB]
#5 3.020 Fetched 8447 kB in 3s (3163 kB/s)
#5 3.020 Reading package lists...
#5 3.053 E: Failed to fetch http://deb.debian.org/debian/dists/buster/main/binary-amd64/by-hash/SHA256/935deda18d5bdc25fb1813d0ec99b6e0e32a084b203e518af0cf7dc79ee8ebda  Hash Sum mismatch
#5 3.053    Hashes of expected file:
#5 3.053     - Filesize:7906864 [weak]
#5 3.053     - SHA256:935deda18d5bdc25fb1813d0ec99b6e0e32a084b203e518af0cf7dc79ee8ebda
#5 3.053     - MD5Sum:ba791e511a2a4b6523ac06f404e32f42 [weak]
#5 3.053    Hashes of received file:
#5 3.053     - SHA256:3dbff74a7005b0214ed17ad72a4724cb91919d8d0221b5297f98f6153606bcaa
#5 3.053     - MD5Sum:f24d4da07e9d1e5bccd9d324cb36dd20 [weak]
#5 3.053     - Filesize:7906864 [weak]
#5 3.053    Last modification reported: Sat, 27 Mar 2021 09:33:56 +0000
#5 3.053    Release file created at: Sat, 27 Mar 2021 09:55:13 +0000
#5 3.053 E: Some index files failed to download. They have been ignored, or old ones used instead.
------
executor failed running [/bin/sh -c apt-get update && apt-get install --no-install-recommends -y   build-essential   libpq-dev]: exit code: 100
Kyrstin answered 28/5, 2021 at 2:52 Comment(1)
I'm having the same problem running on ubuntu:16.04 image... I even tried changing the mirror server... didn't work. Originally this problem was not there... something must have changed. I was able to run apt-get update in an earlier build tag, but it failed again after I updated the apt-get repositories... part of my dockerfile.Protolanguage
S
14

Found this answer from here https://forums.docker.com/t/hash-sum-mismatch-writing-more-data-as-expected/45940/2 This bothered me for a day

RUN echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99custom && \
    echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99custom && \
    echo "Acquire::BrokenProxy    true;" >> /etc/apt/apt.conf.d/99custom

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y \
Sapling answered 24/4, 2023 at 14:2 Comment(2)
me too! 1000 thanks @Kanwar!Incrassate
i dont quite understand why but I started having the same issue this week "out of a blue". This has helped, thanks :)Mencher
K
2

This answer eventually solved my problem. i.e. putting the below code before RUN apt-get update

RUN rm -rf /var/lib/apt/lists/*
RUN apt-get clean
RUN apt-get update -o Acquire::CompressionTypes::Order::=gz
Kyrstin answered 28/5, 2021 at 8:9 Comment(0)
S
1

Seems to be a bad proxy issue. Adding this line before installing the packages helped me.

RUN echo "Acquire::http::Pipeline-Depth 0; \n Acquire::http::No-Cache true; \n Acquire::BrokenProxy    true;" > /etc/apt/apt.conf.d/99fixbadproxy

Referred from this issue in github.

Sacramentalist answered 2/7, 2024 at 6:15 Comment(0)
E
0

from https://forums.docker.com/t/hash-sum-mismatch-writing-more-data-as-expected/45940/2

I tried many suggestions from Google including setting various headers, removing partials, cleaning apt, and deleting the sources files, however none worked.

I found this article that suggested it might be that you are going through a bad proxy: https://github.com/jenkinsci/docker/issues/543 415

The solution is to create a file called badproxy with these lines:

Acquire::http::Pipeline-Depth 0; Acquire::http::No-Cache true; Acquire::BrokenProxy true; then add a line to your Dockerfile to copy it into the apt config folder:

COPY ./badproxy /etc/apt/apt.conf.d/99fixbadproxy

This resolved my issue and the image builds correctly now.

Hope this helps.

Extravagance answered 12/3, 2024 at 5:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.