2

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
Devenol
  • 23
  • 4

4 Answers4

1

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.

nik0x1
  • 152
  • 11
0

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

Faisal Khan
  • 151
  • 1
  • 11
  • Hi, thanks for the reply. – Devenol Apr 22 '22 at 01:24
  • I already try this solution first, however the build process seems to fails and hangs on Apple M1 MacOS similar to: [Building native image using quarkus on a M1 Mac fails](https://stackoverflow.com/questions/68089731/building-native-image-using-quarkus-on-a-m1-mac-fails) – Devenol Apr 22 '22 at 01:32
  • If you see a warning - "The requested images platform (linux/amd64) does not match with the detected host platform (linux/arm64)", here is the workaround - https://github.com/quarkusio/quarkus/issues/16225#issuecomment-1004854142. – Faisal Khan Apr 22 '22 at 13:01
  • I think that work around is for building linux/arm64 image file. While I was trying to build a linux/amd64 image. – Devenol Apr 23 '22 at 17:52
  • A builder image is different from application image. Since M1 uses arm64 chipset, you need arm64 builder image to build a linux compatible application image. – Faisal Khan Apr 24 '22 at 22:24
0

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

allkenang
  • 1,511
  • 15
  • 12
0

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.

Devenol
  • 23
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 16 '23 at 23:15