docker buildx "exec user process caused: exec format error"

9.1k views Asked by At

I am trying to cross-compile a rust app to run on my raspberry pi cluster. I saw buildx from docker was supposed to be able to make this possible. I have a minimal dockerfile right now, it is as follows:

FROM rust
RUN apt-get update
ENTRYPOINT ["echo", "hello world"]

I try to compile this by running the command: docker buildx build --platform=linux/arm/v7 some/repo:tag .

when I do I get the following error:

[+] 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

I feel like I'm missing something pretty basic here, hoping for someone to tell me why such a simple thing isn't working for me.

I am running docker version 20.10.1 on a Ubuntu OS

Thanks in advance!


output of docker buildx inspect --bootstrap:

Name:   default
Driver: docker

Nodes:
Name:      default
Endpoint:  default
Status:    running
Platforms: linux/amd64, linux/386

output of 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
1

There are 1 answers

4
Akihito KIRISAKI On BEST ANSWER

To cross-compile requires qemu-user-static and binfmt-support.

$ sudo apt install -y qemu-user-static binfmt-support

qemu-user-static for user mode emulation of QEMU, and binfmt_misc for switching to QEMU when read other executable binary. Then, tell docker to use them.

$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

You must be afraid to run unknown image as privileged, but the content is safe. Next, create a user in docker for building images.

$ docker buildx create --name sofia # name as you like
$ docker buildx use sofia
$ docker buildx inspect --bootstrap

If you success, buildkit will be pulled:

[+] 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

Available targets expand!

Reference: Building Multi-Architecture Docker Images With Buildx | by Artur Klauser | Medium