cacheport

Error · apt

Fixing apt "Hash Sum mismatch" in Docker builds and CI

apt downloaded an index or package whose hash does not match what the signed release file says. apt refuses to use it, which protects you from corrupted or tampered files.

What you see

build log
E: Failed to fetch http://deb.debian.org/debian/dists/bookworm/main/binary-amd64/by-hash/SHA256/...  Hash Sum mismatch
   Hashes of expected file:
    - Filesize:8789460 [weak]

Common causes

  • A public mirror caught in the middle of a sync, serving new indexes with old release files or the other way round.
  • A transparent proxy serving a stale or truncated copy.
  • A corrupted local apt list cache in a reused image layer.

How to fix it

  1. 01

    Clear the lists and retry

    Start from a clean list cache.

    Dockerfile
    RUN rm -rf /var/lib/apt/lists/* \
     && apt-get update \
     && apt-get install -y --no-install-recommends curl
  2. 02

    Retry downloads

    apt can retry failed fetches.

    Dockerfile
    RUN apt-get -o Acquire::Retries=5 update
  3. 03

    Use a cache that serves consistent snapshots

    A cache that updates release files and indexes together avoids half-synced states.

    Dockerfile
    RUN sed -i "s|http://deb.debian.org|http://acme.cacheport.cc/apt/deb.debian.org|g" /etc/apt/sources.list.d/debian.sources

Other network failures in builds

Start on the free plan

20 GB of cache, every registry, unlimited users. Upgrade when your pipelines outgrow it.