docker 构建错误 - Err:1 http://deb.debian.org/debian stretch/main amd64 unzip amd64 6.0-21+deb9u1 404 Not Found

error in docker build - Err:1 http://deb.debian.org/debian stretch/main amd64 unzip amd64 6.0-21+deb9u1 404 Not Found

我正在我的 MacBook Pro 上做 docker 构建,它总是失败并出现以下错误:

Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
  zip
The following NEW packages will be installed:
  unzip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 170 kB of archives.
After this operation, 547 kB of additional disk space will be used.
Err:1 http://deb.debian.org/debian stretch/main amd64 unzip amd64 6.0-21+deb9u1
  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/pool/main/u/unzip/unzip_6.0-21+deb9u1_amd64.deb  404  Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get install unzip' returned a non-zero code: 100

docker版本: Docker 版本 19.03.8,构建 afacb8b

MacOS:Mojave 10.14.6

Docker文件片段:

FROM debian:latest
RUN apt-get update
RUN apt-get install -y ca-certificates
RUN apt-get install unzip

构建在我们使用 docker-ce=17.09.0~ce-0~ubuntu

的 travis CI 中运行良好

关于如何进一步调试它有什么建议吗?最初我们认为这可能是 debian 方面的暂时问题,但问题一直存在,很可能是我的环境问题。

将您显示的三个 RUN 行组合成一个命令:

FROM debian:latest
RUN apt-get update \
 && apt-get install -y \
      ca-certificates \
      unzip

导致 404 错误的原因有两种。一方面,Docker 将缓存单个 Docker 文件步骤:它看到,从 debian:latest 开始,它已经是 RUN apt-get update,因此它使用来自该命令的版本昨天。另一方面,Debian 相当频繁地更新他们的存储库,更新非常小(请参阅该版本号的 +deb9u1 部分),并且当他们这样做时,他们会从他们的存储库中删除以前的版本。这种组合意味着您可以在一个序列中使用 apt-get update 索引的缓存版本,但它提到的包版本不再存在。

像这样将这些行组合在一起意味着 Docker 将始终 运行 apt-get updateapt-get install 在一起;如果您将包添加到列表中,它将在尝试下载内容之前重新 运行 update 步骤。这避免了这个问题,代价是包列表更改时会增加一些额外的下载时间。