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
To cross-compile requires
qemu-user-static
andbinfmt-support
.qemu-user-static
for user mode emulation of QEMU, andbinfmt_misc
for switching to QEMU when read other executable binary. Then, tell docker to use them.You must be afraid to run unknown image as privileged, but the content is safe. Next, create a user in docker for building images.
If you success,
buildkit
will be pulled:Available targets expand!
Reference: Building Multi-Architecture Docker Images With Buildx | by Artur Klauser | Medium