简体   繁体   中英

Couldn't build application native image with GraalVM

I have built an API in Micronaut and trying to deploy in it GCP Cloud Run as a native graalVM image

This is my Dockerfile

# Stage 1: Build the JAR
FROM gradle:jdk11 as gradle
COPY --chown=gradle . /home/app
WORKDIR /home/app
RUN gradle assemble --no-daemon

# Stage 2: Build the native image
FROM ghcr.io/graalvm/graalvm-ce:latest as graalvm
RUN \
    # Install GraalVM Native Image
    gu install native-image;
COPY --from=gradle /home/app/build/libs/greetings-cloud-run-0.1-all.jar /home/app/server.jar
WORKDIR /home/app
RUN native-image -H:Name=greetings-cloud-run --no-server -cp server.jar com.arun.Application


# Stage 3: Prepare Server
FROM frolvlad/alpine-glibc
RUN apk update && apk add libstdc++
EXPOSE 8080
COPY --from=graalvm /home/app/greetings-cloud-run .
ENTRYPOINT ["./greetings-cloud-run"]

I checked till Stage-2 and the native image is running perfectly fine. I included Stage-3 to run my native-image and ending up with below error

$ docker run a/micro                                                                                                                                  
./greetings-cloud-run: /usr/lib/libstdc++.so.6: no version information available (required by ./greetings-cloud-run)
./greetings-cloud-run: Relink `/usr/lib/libgcc_s.so.1' with `/usr/glibc-compat/lib/libc.so.6' for IFUNC symbol `memset'

Need help on how to run my Native image

It should be standard thing in Micronaut docs,

try https://guides.micronaut.io/latest/micronaut-creating-first-graal-app-maven-java.html

5.2. Creating native image inside Docker
The output following this approach is a Docker image that runs the native image of your application. You don't need to install any additional dependencies.

Building GraalVM native image with Maven
$ ./mvnw package -Dpackaging=docker-native

Ran into this error today. As explained in this gitter thread , the problem is due to not pinning the version of the frolvlad/alpine-glibc docker image. Looks like the newer versions of frolvlad/alpine-glibc are based on alpine 3.13 or newer and those are the versions where this error occurs. Changing frolvlad/alpine-glibc to frolvlad/alpine-glibc:alpine-3.12 fixed it for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM