Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 860
Devenol Avatar asked Sep 16 '25 08:09

Devenol


2 Answers

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.

like image 76
nik0x1 Avatar answered Sep 18 '25 09:09

nik0x1


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

like image 41
allkenang Avatar answered Sep 18 '25 10:09

allkenang