Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker for Mac - Hash sum mismatch

I'm using Docker for Mac with such Dockerfile (only beginning):

# Base image
FROM ubuntu:16.04

RUN export DEBIAN_FRONTEND=noninteractive

# Update packages list and system
RUN apt-get -y update;
RUN apt-get -y upgrade

# Allow to use add-apt-repository command
RUN apt-get -y install software-properties-common locales poppler-utils

and from a few days I'm getting errors like this:

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libk5crypto3_1.13.2+dfsg-5ubuntu2_amd64.deb  Hash Sum mismatch

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/keyutils/libkeyutils1_1.5.9-8ubuntu1_amd64.deb  Hash Sum mismatch

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb5-3_1.13.2+dfsg-5ubuntu2_amd64.deb  Hash Sum mismatch

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libgssapi-krb5-2_1.13.2+dfsg-5ubuntu2_amd64.deb  Writing more data than expected (206672 > 201874) [IP: 91.189.88.152 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get -y install software-properties-common locales poppler-utils' returned a non-zero code: 100

Previously I was using Docker on Windows and got such errors maybe 1 or 2 times in 2 years and now on Mac I'm getting them all the time and cannot build my images.

What can be reason of this? Should I do something on my Mac or maybe change something in my Dockerfile to make it work?

Just to note, I was also playing with changes like this:

# Base image
FROM ubuntu:16.04

RUN export DEBIAN_FRONTEND=noninteractive

RUN echo 'Acquire::Acquire-by-hash "yes";' >> /etc/apt/apt.conf
RUN echo 'Acquire::CompressionTypes::Order "gz";' >> /etc/apt/apt.conf

# Update packages list and system
RUN apt-get -y update
RUN apt-get -y clean
RUN apt-get -y upgrade
RUN apt-get -y clean
RUN apt-get dist-upgrade

# Allow to use add-apt-repository command
RUN apt-get -y install software-properties-common locales poppler-utils

or

# Base image
FROM ubuntu:16.04

RUN export DEBIAN_FRONTEND=noninteractive

RUN rm -rf /var/lib/apt/lists/partial
RUN echo 'Acquire::By-Hash "yes";' >> /etc/apt/apt.conf
RUN echo 'Acquire::CompressionTypes::Order:: "gz";' >> /etc/apt/apt.conf

# Update packages list and system
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get -y clean
RUN apt-get -y upgrade
RUN apt-get -y clean
RUN apt-get dist-upgrade

# Allow to use add-apt-repository command
RUN apt-get -y install software-properties-common
RUN apt-get -y install locales poppler-utils

but it didn't change this.

I've tested it on Windows and it is working perfectly fine. The funny thing is that when I change FROM ubuntu:16.04 to FROM ubuntu:17.10 on MacOS it will also work without any problems so it seemed that somehow packages are taken not from 16.04 but 17.10 when I have FROM ubuntu:16.04

I've already:

  • restarted my Mac
  • restarted Docker
  • removed all data
  • reset to factory defaults
  • uninstalled and installed again Docker
  • downgraded from mac49 to 17.12.0-ce-mac46 (21698)
  • removed all images / containers and build them again

None of those change the thing. The strange is that it worked before on my MacOS (I've build images about 20-30 times before and it was fine) and also now maybe once every 100 times it would succeed now to build image but obviously this is not the best solution.

As a temporary workaround I've built all the images on Windows and pushed them to Docker hub and then pull them on MacOS but again this is only workaround and not the solution.

like image 431
Marcin Nabiałek Avatar asked Jan 03 '23 20:01

Marcin Nabiałek


2 Answers

My sense is you are hitting a known issue Ubuntu bug #972077 that I have also encountered.

Apparently, the apt repository format is subject to race conditions when a mirror is updated. This problem particularly affects repositories that change rapidly, such as a development release and align with your symptom description between 16.04 and 17.10.

The recommended solution that worked for me was to run:

apt-get clean
rm -r /var/lib/apt/lists/*
# The blog below also recommends to change your compression
apt-get update -o Acquire::CompressionTypes::Order::=gz 

Note: This appears to be confounded by the cache you are pulling from. Thus in some cases, it appears you need to change your download repo to update your cache.

References:

Package Cloud Blog Post:

  • https://blog.packagecloud.io/eng/2016/03/21/apt-hash-sum-mismatch/

Ubuntu thread on the issue:

  • https://askubuntu.com/questions/41605/trouble-downloading-packages-list-due-to-a-hash-sum-mismatch-error

Unix Thread on this issue

  • https://unix.stackexchange.com/questions/116641/how-do-you-fix-apt-get-update-hash-sum-mismatch/273441#273441

I hope the above helps point you in the right direction.

like image 51
Technophobe01 Avatar answered Jan 05 '23 10:01

Technophobe01


Its hard to say what could be wrong here, since you have already tried a lot of things yourself. One thing I could suggest is to change the mirror. You can find the list of mirrors from

https://launchpad.net/ubuntu/+archivemirrors

Then use it like below

# Base image 
FROM ubuntu:16.04 

RUN sed -i '1ideb mirror.onet.pl/pub/mirrors/… xenial main' /etc/apt/sources.list 
RUN sed -i '1ideb-src mirror.onet.pl/pub/mirrors/… xenial main' /etc/apt/sources.list 

Another option you could try is to use apt instead of apt-get

RUN apt update && apt upgrade
RUN apt install -y software-properties-common locales poppler-utils

Another option you could try is using a single RUN statement

RUN apt update && apt upgrade && apt install -y software-properties-common locales poppler-utils

All this may not answer why it is happening, but it may give you a workaround

like image 38
Tarun Lalwani Avatar answered Jan 05 '23 10:01

Tarun Lalwani