![arm64 多架构 docker 构建在 apt 更新上失败](https://linux22.com/image/933489/arm64%20%E5%A4%9A%E6%9E%B6%E6%9E%84%20docker%20%E6%9E%84%E5%BB%BA%E5%9C%A8%20apt%20%E6%9B%B4%E6%96%B0%E4%B8%8A%E5%A4%B1%E8%B4%A5.png)
我正在尝试基于 ubuntu 20.04 创建一个多架构容器。apt update
添加新架构后,Docker 构建失败。这是我目前的 docker 文件:
# base image
FROM ubuntu:20.04
# create user
RUN useradd -rm -d /home/embed -s /bin/bash -g root -G sudo -u 1001 embed
RUN mkdir -p /home/embed/software
RUN mkdir -p /home/embed/data
# symlink python3 to python
RUN ln -s /usr/bin/python3 /usr/bin/python
# install arm64 cross-compilation toolchain
RUN dpkg --add-architecture arm64
RUN apt-get update
...
达到后apt-get update
,我得到以下输出:
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Ign:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Ign:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Ign:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
Ign:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Ign:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Ign:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Err:5 http://security.ubuntu.com/ubuntu focal-security/main arm64 Packages
404 Not Found [IP: 91.189.88.142 80]
Ign:6 http://security.ubuntu.com/ubuntu focal-security/restricted arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Ign:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Ign:7 http://security.ubuntu.com/ubuntu focal-security/universe arm64 Packages
Ign:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Err:8 http://archive.ubuntu.com/ubuntu focal/multiverse arm64 Packages
404 Not Found [IP: 91.189.88.142 80]
Ign:9 http://archive.ubuntu.com/ubuntu focal/restricted arm64 Packages
Ign:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
Ign:10 http://archive.ubuntu.com/ubuntu focal/universe arm64 Packages
Ign:11 http://archive.ubuntu.com/ubuntu focal/main arm64 Packages
Ign:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Ign:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
Err:12 http://archive.ubuntu.com/ubuntu focal-updates/universe arm64 Packages
404 Not Found [IP: 91.189.88.142 80]
Ign:13 http://archive.ubuntu.com/ubuntu focal-updates/main arm64 Packages
Ign:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse arm64 Packages
Ign:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted arm64 Packages
Ign:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
Err:16 http://archive.ubuntu.com/ubuntu focal-backports/universe arm64 Packages
404 Not Found [IP: 91.189.88.142 80]
Reading package lists...
E: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/main/binary-arm64/Packages 404 Not Found [IP: 91.189.88.142 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/multiverse/binary-arm64/Packages 404 Not Found [IP: 91.189.88.142 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/universe/binary-arm64/Packages 404 Not Found [IP: 91.189.88.142 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/universe/binary-arm64/Packages 404 Not Found [IP: 91.189.88.142 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
似乎所有 arm64 存储库都被忽略或未找到。我发现这个问题有完全相同的问题,但没有提供解决方案。
在执行之前,我是否必须对所有 apt 源进行 arch-qualifiedapt-update
在执行类似这个答案说?有没有更自动化的方法适合构建docker镜像?
提前致谢
答案1
我仍然不知道是否有更好的方法,但我基本上做了已经做的事情这里,但适用于 20.04。Dockerfile 现在是:
# base image
FROM ubuntu:20.04
...
# 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
RUN apt-get update
...