docker buildx "exec user process caused: exec format error"
docker buildx "exec user process caused: exec format error"
我正在尝试将 Rust 应用程序交叉编译到 运行 我的 raspberry pi 集群上。我看到来自 docker 的 buildx 应该能够使这成为可能。我现在有一个最小的 docker 文件,如下所示:
FROM rust
RUN apt-get update
ENTRYPOINT ["echo", "hello world"]
我尝试通过 运行 编译这个命令:docker buildx build --platform=linux/arm/v7 some/repo:tag .
当我这样做时,出现以下错误:
[+] Building 0.9s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 102B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/rust:latest 0.7s => CACHED [1/2] FROM docker.io/library/rust@sha256:65e254fff15478af71d342706b1e73b26fd883f3432813c129665a97a74e2278
0.0s => ERROR [2/2] RUN apt-get update 0.2s
------
> [2/2] RUN apt-get update:
#5 0.191 standard_init_linux.go:219: exec user process caused: exec format error
------ error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c apt-get update]: exit code: 1
我觉得我在这里遗漏了一些非常基本的东西,希望有人告诉我为什么这么简单的东西对我不起作用。
我正在 运行宁 docker 版本 20.10.1 Ubuntu OS
提前致谢!
docker buildx inspect --bootstrap
的输出:
Name: default
Driver: docker
Nodes:
Name: default
Endpoint: default
Status: running
Platforms: linux/amd64, linux/386
ls -l /proc/sys/fs/binfmt_misc/
的输出:
total 0
--w------- 1 root root 0 Dec 19 07:29 register
-rw-r--r-- 1 root root 0 Dec 19 07:29 status
交叉编译需要 qemu-user-static
和 infmt-support
。
$ sudo apt install -y qemu-user-static binfmt-support
qemu-user-static
用于 QEMU 的用户模式仿真,binfmt_misc
用于在读取其他可执行二进制文件时切换到 QEMU。然后,告诉 docker 使用它们。
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
你一定害怕 运行 未知图像作为特权,但是 the content is safe。接下来,在 docker 中创建一个用于构建图像的用户。
$ docker buildx create --name sofia # name as you like
$ docker buildx use sofia
$ docker buildx inspect --bootstrap
如果成功,buildkit
将被拉取:
[+] Building 9.4s (1/1) FINISHED
=> [internal] booting buildkit 9.4s
=> => pulling image moby/buildkit:buildx-stable-1 8.7s
=> => creating container buildx_buildkit_sofia0 0.7s
Name: sofia
Driver: docker-container
Nodes:
Name: sofia0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
可用目标扩展!
参考:
Building Multi-Architecture Docker Images With Buildx | by Artur Klauser | Medium
我正在尝试将 Rust 应用程序交叉编译到 运行 我的 raspberry pi 集群上。我看到来自 docker 的 buildx 应该能够使这成为可能。我现在有一个最小的 docker 文件,如下所示:
FROM rust
RUN apt-get update
ENTRYPOINT ["echo", "hello world"]
我尝试通过 运行 编译这个命令:docker buildx build --platform=linux/arm/v7 some/repo:tag .
当我这样做时,出现以下错误:
[+] Building 0.9s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 102B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/rust:latest 0.7s => CACHED [1/2] FROM docker.io/library/rust@sha256:65e254fff15478af71d342706b1e73b26fd883f3432813c129665a97a74e2278
0.0s => ERROR [2/2] RUN apt-get update 0.2s
------
> [2/2] RUN apt-get update:
#5 0.191 standard_init_linux.go:219: exec user process caused: exec format error
------ error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c apt-get update]: exit code: 1
我觉得我在这里遗漏了一些非常基本的东西,希望有人告诉我为什么这么简单的东西对我不起作用。
我正在 运行宁 docker 版本 20.10.1 Ubuntu OS
提前致谢!
docker buildx inspect --bootstrap
的输出:
Name: default
Driver: docker
Nodes:
Name: default
Endpoint: default
Status: running
Platforms: linux/amd64, linux/386
ls -l /proc/sys/fs/binfmt_misc/
的输出:
total 0
--w------- 1 root root 0 Dec 19 07:29 register
-rw-r--r-- 1 root root 0 Dec 19 07:29 status
交叉编译需要 qemu-user-static
和 infmt-support
。
$ sudo apt install -y qemu-user-static binfmt-support
qemu-user-static
用于 QEMU 的用户模式仿真,binfmt_misc
用于在读取其他可执行二进制文件时切换到 QEMU。然后,告诉 docker 使用它们。
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
你一定害怕 运行 未知图像作为特权,但是 the content is safe。接下来,在 docker 中创建一个用于构建图像的用户。
$ docker buildx create --name sofia # name as you like
$ docker buildx use sofia
$ docker buildx inspect --bootstrap
如果成功,buildkit
将被拉取:
[+] Building 9.4s (1/1) FINISHED
=> [internal] booting buildkit 9.4s
=> => pulling image moby/buildkit:buildx-stable-1 8.7s
=> => creating container buildx_buildkit_sofia0 0.7s
Name: sofia
Driver: docker-container
Nodes:
Name: sofia0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
可用目标扩展!
参考: Building Multi-Architecture Docker Images With Buildx | by Artur Klauser | Medium