无法构建多架构docker镜像

无法构建多架构docker镜像

我想在我的 Intel 笔记本电脑上构建一个 docker 镜像。该镜像将部署在 x86/x64 和 arm64 主机上。docker 文件使用ubuntu:20.04基础镜像。我尝试使用以下命令构建镜像:

docker buildx build . --no-cache --progress plain --platform linux/arm64/v8,linux/amd64 -t mytag

但它失败并出现错误:

#10 [linux/arm64  3/17] RUN apt update &&     apt install -y --no-install-recommends software-properties-common &&     add-apt-repository -y ppa:ubuntu-toolchain-r/test &&     add-apt-repository -y "deb http://security.ubuntu.com/ubuntu xenial-security main" &&     add-apt-repository -y ppa:deadsnakes/ppa  &&     apt-get update &&     apt-get install -y --no-install-recommends     sudo     usbutils     libcanberra-gtk3-module ...*
#10 191.3 Reading package lists...
#10 195.6 E: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/main/binary-arm64/Packages  404  Not Found [IP: 185.125.190.39 80]
#10 195.6 E: Some index files failed to download. They have been ignored, or old ones used instead.
#10 ERROR: process "/bin/sh -c apt update &&     apt install -y --no-install-recommends software-properties-common &&     add-apt-repository -y ppa:ubuntu-toolchain-r/test &&     add-apt-repository -y \"deb http://security.ubuntu.com/ubuntu xenial-security main\" &&     add-apt-repository -y ppa:deadsnakes/ppa  &&     apt-get update &&     apt-get install -y --no-install-recommends     sudo     usbutils     libcanberra-gtk3-module ..." did not complete successfully: exit code: 100

参照回答时,我在我的中添加了以下几行Dockerfile

## add arm64 architecture
RUN apt-get update
RUN dpkg --add-architecture arm64

## arch-qualify the current repositories
RUN sed -i "s/deb h/deb [arch=amd64] h/g" /etc/apt/sources.list

## add arm64's repos
RUN echo "# arm64 repositories" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal main restricted" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal universe" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates universe" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal multiverse" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates multiverse" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security main restricted" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security universe" >> /etc/apt/sources.list
RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security multiverse" >> /etc/apt/sources.list

但现在它给出了以下错误:

#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal/main/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-updates/multiverse/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-backports/main/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-security/multiverse/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Some index files failed to download. They have been ignored, or old ones used instead.

#23 19.23 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:51
#23 19.23 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:51
#23 19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:14 and /etc/apt/sources.list:53
#23 19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list:55
#23 19.24 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:8 and /etc/apt/sources.list:52
#23 19.24 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:8 and /etc/apt/sources.list:52
#23 19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:16 and /etc/apt/sources.list:54
#23 19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:26 and /etc/apt/sources.list:56
#23 19.24 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
#23 19.24 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
#23 19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
#23 19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
#23 19.24 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:44 and /etc/apt/sources.list:58
#23 19.24 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:44 and /etc/apt/sources.list:58
#23 19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:46 and /etc/apt/sources.list:59
#23 19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:48 and /etc/apt/sources.list:60
#23 ERROR: process "/bin/sh -c apt-get update" did not complete successfully: exit code: 100

#9 [linux/amd64  2/31] RUN apt-get update
#9 39.27 Get:16 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3553 kB]
#9 CANCELED
------
 > [linux/arm64 16/31] RUN apt-get update:
19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:16 and /etc/apt/sources.list:54
19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:26 and /etc/apt/sources.list:56
19.24 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
19.24 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:34 and /etc/apt/sources.list:57
19.24 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:44 and /etc/apt/sources.list:58
19.24 W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:44 and /etc/apt/sources.list:58
19.24 W: Target Packages (universe/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:46 and /etc/apt/sources.list:59
19.24 W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:48 and /etc/apt/sources.list:60
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:31
--------------------
  29 |     RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security multiverse" >> /etc/apt/sources.list
  30 |     
  31 | >>> RUN apt-get update
  32 |     # Set environment variables to avoid interactive prompts during installation
  33 |     ENV DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update" did not complete successfully: exit code: 100

我在这里遗漏了什么?

更新 1

我忘了说我能够使用以下命令成功构建与我的笔记本电脑相同架构(x86 / x64 或 amd64)的图像:

docker build . --no-cache --progress plain -t mytag

当我尝试为 arm64/多架构构建时,问题出现了。

更新 2

我尝试通过注释掉与404错误对应的行:

# RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal main restricted" >> /etc/apt/sources.list   
# RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates multiverse" >> /etc/apt/sources.list
# RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse" >> /etc/apt/sources.list
# RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security multiverse" >> /etc/apt/sources.list

但仍然有同样的错误。

这是预料之中的,因为这种404情况发生在 amd64 软件包中,而不是 arm64 软件包中:

#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal/main/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-updates/multiverse/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-backports/main/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]
#23 19.23 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal-security/multiverse/binary-amd64/Packages  404  Not Found [IP: 185.125.190.39 80]

但是我猜测为什么它对于 amd64 包失败了,因为在我为 arm64 添加更改之前它曾经成功构建过图像。

相关内容