I used the hello word Java app produced with gradle init. And I want to run it in docker. Here is my docker file:
FROM gradle:7.5.1-jdk11 AS builder
COPY . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle installDist
FROM openjdk:18.0.2.1-oracle
RUN microdnf install findutils
COPY --from=builder /home/gradle/src/build/install/app/ /app/
WORKDIR /app
CMD bin/app
It runs ok only when the second running image has a Java18. I'm really confused here, the first builder image has Java11. Why the gradle in image isn't configured to use system's JDK version? If it always uses it's own JDK. Why bother shipping a JDK11 with the gradle image?
Also, docker noob question: There are so many JDK / JRE images out there, how do you guys pick which one to use? Any preference ranking or something similar?
I did another try. Only use the first part of the docker file
FROM gradle:7.5.1-jdk11 AS builder
COPY . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle installDist
Then docker build --tag second-try .
Then docker run -it second-try /bin/bash
I went into the build/install/app/lib folder and unpacked the app.jar jar xf app.jar to get the compiled class file. Then javap -v App.class | grep major to get the compiling JDK version. The version is 62 which is Java18.