1

My goal is to run native image file created by GraalVM with Alpine docker because the Docker Image with GraalVM JDK size is too big, around 587.82 MB

What I've did:

  1. Use GraalVM JDK, and it works when I try to call ./main
FROM ghcr.io/graalvm/native-image:java11-21.2
WORKDIR /app
COPY ./src/main/java/ /app
RUN javac Main.java
RUN native-image Main

FROM ghcr.io/graalvm/jdk:java11-21.2
WORKDIR /app
COPY --from=0 /app/main /app/main
CMD ./main

The problem is when I try to switch GraalVM JDK to Alpine

FROM ghcr.io/graalvm/native-image:java11-21.2
WORKDIR /app
COPY ./src/main/java/ /app
RUN javac Main.java
RUN native-image Main

FROM alpine:3.15
WORKDIR /app
COPY --from=0 /app/main /app/main
CMD ./main

It throws an error native-image_1 | /bin/sh: ./main: not found

Jason Rich Darmawan
  • 1,607
  • 3
  • 14
  • 31
  • AFAIK If you compile binary on default Linux, it compiles with dependencies to `stdlibc` or something like that. Whereas `Alpine Linux` has no these libraries, it uses `musl` instead. This may the issue. – lospejos Jun 20 '22 at 21:38
  • Does this answer your question? [Docker Alpine executable binary not found even if in PATH](https://stackoverflow.com/questions/66963068/docker-alpine-executable-binary-not-found-even-if-in-path) – Egor Jan 03 '23 at 23:20

1 Answers1

0

Replace RUN native-image Main with RUN native-image --static Main.

Explanation: Alpine uses a different glibc implementation from the linux used to build the binary. When you use the option --static all glibc from the linux you build are going to be included in the binary.

If you need more detail see https://github.com/oracle/graal/issues/386