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
Docker throws error standard_init_linux.go:228: exec user process caused: exec format error when there are issues with executable file format. It could happen due to these reasons – You forgot to put #!/bin/bash at the top of shell files. There is a space before shebang ( #!/bin/bash ). Using #!/bin/bash instead of #!/bin/ash for alpine images.
We created the Dockerfile on a Windows machine. Saving the Dockerfile used the default Windows file format. This caused the Docker build to fail on a Linux machine. What we did to fix is converting the file format to UNIX style using dos2unix:
The problem: a wrong file format caused by Windows. Let’s fix this! Docker outputs all build steps when creating an image based on a Dockerfile. The “exec user process caused „no such file or directory“” issue occurred when executing a shell script.
A Docker file is the text document that use all the commands that a user could call on the command line to assemble an image.Also in Docker file we can write the instructions to build a Docker image. The sign of this error is that the docker entrypoint script was missing a shebang. So to fix the error we add the shebang in the script.
To cross-compile requires qemu-user-static
and infmt-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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With