我正在尝试使用docker buildx构建一个多平台(amd64、arm64和armv7)映像。因为我使用的是运行Ubuntu 18.04的amd64机器,所以我按照Docker网站上的说明,通过以下方式安装了qemu:
sudo apt安装qemu用户
但是,当我执行前面的命令时,会出现一个奇怪的错误。更具体地说,binfmt-support服务似乎有问题。以下是完整的日志:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
The following additional packages will be installed:
binfmt-support qemu-user-binfmt
The following NEW packages will be installed:
binfmt-support qemu-user qemu-user-binfmt
0 upgraded, 3 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/7.409 kB of archives.
After this operation, 63,4 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Selecting previously unselected package binfmt-support.
(Reading database ... 245278 files and directories currently installed.)
Preparing to unpack .../binfmt-support_2.1.8-2_amd64.deb ...
Unpacking binfmt-support (2.1.8-2) ...
Selecting previously unselected package qemu-user.
Preparing to unpack .../qemu-user_1%3a2.11+dfsg-1ubuntu7.21_amd64.deb ...
Unpacking qemu-user (1:2.11+dfsg-1ubuntu7.21) ...
Selecting previously unselected package qemu-user-binfmt.
Preparing to unpack .../qemu-user-binfmt_1%3a2.11+dfsg-1ubuntu7.21_amd64.deb ...
Unpacking qemu-user-binfmt (1:2.11+dfsg-1ubuntu7.21) ...
Setting up binfmt-support (2.1.8-2) ...
Job for binfmt-support.service failed because the control process exited with error code.
See "systemctl status binfmt-support.service" and "journalctl -xe" for details.
invoke-rc.d: initscript binfmt-support, action "start" failed.
● binfmt-support.service - Enable support for additional executable binary formats
Loaded: loaded (/lib/systemd/system/binfmt-support.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-02-05 17:20:29 CET; 4ms ago
Docs: man:update-binfmts(8)
Process: 7766 ExecStart=/usr/sbin/update-binfmts --enable (code=exited, status=2)
Main PID: 7766 (code=exited, status=2)
feb 05 17:20:29 XPS-15-9570 systemd[1]: Starting Enable support for additional executable binary formats...
feb 05 17:20:29 XPS-15-9570 update-binfmts[7766]: update-binfmts: warning: unable to close /proc/sys/fs/binfmt_misc/register: No such file or directory
feb 05 17:20:29 XPS-15-9570 update-binfmts[7766]: update-binfmts: exiting due to previous errors
feb 05 17:20:29 XPS-15-9570 systemd[1]: binfmt-support.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
feb 05 17:20:29 XPS-15-9570 systemd[1]: binfmt-support.service: Failed with result 'exit-code'.
feb 05 17:20:29 XPS-15-9570 systemd[1]: Failed to start Enable support for additional executable binary formats.
Setting up qemu-user (1:2.11+dfsg-1ubuntu7.21) ...
Setting up qemu-user-binfmt (1:2.11+dfsg-1ubuntu7.21) ...
update-binfmts: warning: current package is qemu-user-binfmt, but binary format already installed by qemu-user-static
update-binfmts: exiting due to previous errors
dpkg: error processing package qemu-user-binfmt (--configure):
installed qemu-user-binfmt package post-installation script subprocess returned error exit status 2
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for neon-settings (0.0+p18.04+git20191212.1343) ...
Processing triggers for systemd (237-3ubuntu10.33) ...
Errors were encountered while processing:
qemu-user-binfmt
E: Sub-process /usr/bin/dpkg returned an error code (1)
尽管如此,我还是试着按照通常的程序进行,即:
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap
其中最后一个命令的输出是:
[+] Building 5.0s (1/1) FINISHED
=> [internal] booting buildkit 5.0s
=> => pulling image moby/buildkit:buildx-stable-1 4.3s
=> => creating container buildx_buildkit_mybuilder0 0.7s
Name: mybuilder
Driver: docker-container
Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/386
如您所见,“linux/amd64”和“linux/386”是唯一可用的平台,但是我还需要为“linux/arm64”和“linux/arm/v7”平台构建映像。我一直在寻找解决这个问题的方法,虽然我没有找到任何有效的方法
看起来我可以通过运行以下命令解决部分问题:
sudo apt purge --auto-remove qemu-user qemu-user-binfmt binfmt-support
然后重新安装它们。事实上,再次运行这个命令:
sudo apt install qemu-user
完全没有错误:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
The following additional packages will be installed:
binfmt-support qemu-user-binfmt
The following NEW packages will be installed:
binfmt-support qemu-user qemu-user-binfmt
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/7.409 kB of archives.
After this operation, 63,4 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Selecting previously unselected package binfmt-support.
(Reading database ... 245437 files and directories currently installed.)
Preparing to unpack .../binfmt-support_2.1.8-2_amd64.deb ...
Unpacking binfmt-support (2.1.8-2) ...
Selecting previously unselected package qemu-user.
Preparing to unpack .../qemu-user_1%3a2.11+dfsg-1ubuntu7.21_amd64.deb ...
Unpacking qemu-user (1:2.11+dfsg-1ubuntu7.21) ...
Selecting previously unselected package qemu-user-binfmt.
Preparing to unpack .../qemu-user-binfmt_1%3a2.11+dfsg-1ubuntu7.21_amd64.deb ...
Unpacking qemu-user-binfmt (1:2.11+dfsg-1ubuntu7.21) ...
Setting up binfmt-support (2.1.8-2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/binfmt-support.service → /lib/systemd/system/binfmt-support.service.
Setting up qemu-user (1:2.11+dfsg-1ubuntu7.21) ...
Setting up qemu-user-binfmt (1:2.11+dfsg-1ubuntu7.21) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for neon-settings (0.0+p18.04+git20191212.1343) ...
Processing triggers for systemd (237-3ubuntu10.38) ...
同样,system ctl状态binfmt-support.service
的输出如预期:
● binfmt-support.service - Enable support for additional executable binary formats
Loaded: loaded (/lib/systemd/system/binfmt-support.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2020-02-10 11:42:23 CET; 1min 11s ago
Docs: man:update-binfmts(8)
Main PID: 7161 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/binfmt-support.service
feb 10 11:42:23 XPS-15-9570 systemd[1]: Starting Enable support for additional executable binary formats...
feb 10 11:42:23 XPS-15-9570 systemd[1]: Started Enable support for additional executable binary formats.
但是,部分问题仍然存在,因为运行这三个命令后的输出:
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap
与以前相同,即:
[+] Building 2.6s (1/1) FINISHED
=> [internal] booting buildkit 2.6s
=> => pulling image moby/buildkit:buildx-stable-1 2.0s
=> => creating container buildx_buildkit_mybuilder0 0.6s
Name: mybuilder
Driver: docker-container
Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/386
为什么?为什么它显示linux/amd64
和linux/386
是唯一可用的平台?
docker context ls
的输出是:
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
我也试过在qemu安装后重启docker,但没有成功。另外,在docker Buildx命令中指定目标平台:
docker buildx build -t <mytag> --platform linux/amd64,linux/arm64,linux/arm/v7 --load .
导致此错误的原因:
[+] Building 0.6s (5/20)
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [linux/arm/v7 internal] load metadata for docker.io/alegeno92/opencv_python3:3.4.2 0.6s
=> CANCELED [linux/arm64 internal] load metadata for docker.io/alegeno92/opencv_python3:3.4.2 0.6s
=> CANCELED [linux/amd64 internal] load metadata for docker.io/alegeno92/opencv_python3:3.4.2 0.6s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to load LLB: runtime execution on platform linux/arm/v7 not supported
顺便说一下,我的内核版本是4.15.0-76-generic
对于github CI,添加以下插件为我解决这个问题
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all
根据第一个错误标记此答案。命令已根据更新https://docs.docker.com/buildx/working-with-buildx/.
QEMU是一个跨平台模拟器,负责为不同的体系结构(通过binfmt_misc处理程序)寻找二进制文件。
将为一些人节省一些时间,首先使用此命令:
docker run --privileged --rm tonistiigi/binfmt --install all
首先运行多拱容器
html prettyprint-override">docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx rm builder
docker buildx create --name builder --driver docker-container --use
docker buildx inspect --bootstrap
你已经经历过了吗?干杯,奥利维尔
问题内容: 我尝试在构建映像的同时使用Docker安装软件,然后得到了。 我使用的Dockerfile 有没有一种方法可以在Dockerfile中运行docker命令来创建映像? 问题答案: 您的问题不在于Docker命令,因为它在错误消息中表示您的Docker守护程序未运行,或者由于某些配置问题而无法连接到它。 您刚刚安装了Docker吗?您是否完成了《安装指南》中的所有步骤? 您可以使用或来测
我正在尝试基于ruby: 3.0构建Docker映像。在Dockerfile中,运行“RUN bundle install”时,开始安装依赖项,直到显示错误: Gem::Ext::BuildError:错误:未能生成Gem本机扩展#10 34.20 34.20当前目录:/usr/local/bundle/gems/tiny_tds-2.1.5/ext/tiny-tds#10 34.2/usr/lo
问题内容: 我是Docker的新手,所以请允许我描述我执行的步骤。我在OS X上使用Docker(不是Docker工具箱)。我使用以下命令从Dockerfile构建了映像 Docker确认构建成功。 但是,我在任何地方都找不到图像。我看了这个问题,但是答案是针对Docker工具箱的,并且没有公认的答案所建议的文件夹。 问题答案: 您将可以通过以下命令查看您的docker映像: 并检查哪些容器正在d
我参考了Docker官方文档:创建基本映像并执行以下命令: 我收到上一个命令的错误消息,图像“raring”为空,0B。 由于映像是空的,我将目标从 /dev/null更改为。/rootfs参考此页面:如何为Docker制作自己的基本映像? 但Debootstrap无法获取发布: 使用wget和我的浏览器,我发现“http://archive.ubuntu.com/ubuntu/dists/rar
问题内容: 我正在尝试 使用 官方链接中提到 的API 构建 docker镜像 。 但是我无法获得文件中的内容:示例请求: 有几件事使我感到困惑, 1)在哪里提到 Dockerfile 的 路径 ? 2)“归档文件必须在归档文件的根目录中包含一个构建指令文件,通常称为Dockerfile。” 来自docker docs的此声明,这里的困惑 是存档的根 是 什么 ? 3) 构建图像的详细命令 是什么