dockerquarkus-native

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

Solution

  • 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.