这个答案最终解决了我的问题。即将以下代码放在
我使用的是macOS 11.4和Docker 3.3.3。我的docker文件看起来像
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
我尝试过用Python对Docker镜像的不同标签,也尝试过用--no-cache
命令创建镜像,但每次尝试构建镜像时,我都会得到错误Hash Sum mismatch
这是我的日志:
[+] 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
任何形式的帮助都将不胜感激。提前谢谢。
从这里找到了这个答案https://forums.docker.com/t/hash-sum-mismatch-writing-more-data-as-expected/45940/2这困扰了我一天
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
RUN apt-get update
之前
RUN rm -rf /var/lib/apt/lists/*
RUN apt-get clean
RUN apt-get update -o Acquire::CompressionTypes::Order::=gz