Building quarkus native Linux/amd64 (x86_64) image from Apple M1 (Arm)

2k views Asked by At

I am trying to build Quarkus 2.8.0 for x86 platfom of native docker container from Apple M1 Macbook and deploy it in Linux amd64 Portainer. I was able to build the native image and when checking the file

file target/simple-app-1.0.0-SNAPSHOT-runner

the output is:

target/simple-app-1.0.0-SNAPSHOT-runner: Mach-O 64-bit executable x86_64

And then I am building docker container using Dockerfile.native-micro file, and push to my local registry using this command:

docker buildx build -t local-registry/repo/simple-app:latest-x86_64 -f src/main/docker/Dockerfile.native-micro --push --platform=linux/amd64 .

The build process finished successfully without error or warning, and when I check in the local registry the container is created.

The problem appear when I was trying to deploy the container in my Linux amd64 server with Portainer. The container is unable to start, and the log output is:

standard_init_linux.go:219: exec user process caused: exec format error
4

There are 4 answers

2
nik0x1 On BEST ANSWER

First, you need to build an executable file for the x86_64 (for that use an image with graalvm or mandrel for x86_64):

./mvnw clean package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.3.2-java17-amd64 -DskipTests

Second, you need to build your image for x86_64:

docker buildx build --platform linux/amd64 -f src/main/docker/Dockerfile.native -t your-image-amd64 .

Note: build is slow.

5
Faisal Khan On

The native image that you created is Mac native, it will not run in Linux. You should rather build your image using

quarkus build --native -Dquarkus.native.container-build=true

1
Devenol On

After trying all the suggested solutions, I decided to build the native image in a separate linux machine with an X86_64 processors.

Thanks all.

1
allkenang On

The reason why your build fails is that when building from an M1 Mac (even with -Dquarkus.native.container-build=true), the native Linux binary is based on arm64.

When you run this native binary in a Linux environment that runs x86 Linux, you get the exec format error

To fix this, you need to enable multi arch support for your native build.

if you use Maven:

./mvnw quarkus:add-extension -Dextensions='container-image-docker'

then build by passing in the buildx props like so

./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.docker.buildx.platform=linux/amd64 -DskipTests

Documentation is here: https://quarkus.io/guides/container-image