shai engel
shai engel

Reputation: 81

docker cross-compilation - missing platforms in buildx

i'm trying to build a Dockerfile on Centos7 x86_64. the docker image should run on arm64 linux machine. in order to prepare my machine for the cross-compilation i checked:

>docker buildx ls

NAME/NODE DRIVER/ENDPOINT STATUS  PLATFORMS
default * docker
  default default         running linux/amd64, linux/386

i am trying to add linux/arm64 to the platform list but nothing works

  1. i followed: https://docs.docker.com/build/buildx/install/

    i downloaded from arm https://github.com/docker/buildx/releases from to /usr/libexec/docker/cli-plugins/docker-buildx

    the consequence was that i could run "docker buildx ls" at all. so i revered it.

  2. i set docker to experimental true

  3. i work on docker version 20.10.18

  4. i gave full permission to /usr/libexec/docker/cli-plugins/docker-buildx

  5. i called

    docker run --privileged --rm tonistiigi/binfmt --install all

    the result is:

    installing: arm64 cannot register "/usr/bin/qemu-aarch64" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: arm cannot register "/usr/bin/qemu-arm" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: riscv64 cannot register "/usr/bin/qemu-riscv64" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: mips64le cannot register "/usr/bin/qemu-mips64el" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: mips64 cannot register "/usr/bin/qemu-mips64" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: s390x cannot register "/usr/bin/qemu-s390x" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument installing: ppc64le cannot register "/usr/bin/qemu-ppc64le" to /proc/sys/fs/binfmt_misc/register: write /proc/sys/fs/binfmt_misc/register: invalid argument { "supported": [ "linux/amd64", "linux/386" ], "emulators": [ "jexec", "kshcomp" ] }

After all that, it seems that with Docker Desktop the missing platforms appears.

Can i add arm64 without Docker Desktop?

BTW, i tried building Dockerfile like this:

FROM ubuntu
ARG TARGETARCH=arm64
ARG CPUARCH=aarch64
RUN mkdir -p config/cmap

and i ran the build command with this: docker build --platform linux/arm64 .

it failed with this message:

Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM ubuntu
latest: Pulling from library/ubuntu
00f50047d606: Already exists
Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
Status: Downloaded newer image for ubuntu:latest
 ---> 21735dab04ba
Step 2/4 : ARG TARGETARCH=arm64
 ---> [Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
 ---> Running in 7de7701f6b3a
Removing intermediate container 7de7701f6b3a
 ---> b4438f9c8791
Step 3/4 : ARG CPUARCH=aarch64
 ---> [Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
 ---> Running in b3aa3d8c24f7
Removing intermediate container b3aa3d8c24f7
 ---> 5be105ca2646
Step 4/4 : RUN mkdir -p config/cmap
 ---> [Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
 ---> Running in 4be5019859f8
standard_init_linux.go:228: exec user process caused: exec format error
The command '/bin/sh -c mkdir -p config/cmap' returned a non-zero code: 1

it seems that unless there's a way to set linux/arm64 in buildx platform no cross compilation of docker build could work

Upvotes: 1

Views: 1773

Answers (1)

shai engel
shai engel

Reputation: 81

Kernel version should be newer than 4.8. Centos 7 with kernel 3.10 doesn't support cross compilation on docker images

Upvotes: 4

Related Questions