4 ms·
I'm not sure this is the issue you are referencing, but you can use multi-stage Docker image builds to avoid bundling the JDK in the final Docker image: FROM
by Longwelwind 7y ago
I'm not sure this is the issue you are referencing, but you can use multi-stage Docker image builds to avoid bundling the JDK in the final Docker image:
FROM openjdk:jdk AS build
COPY . .
RUN mvn package
FROM openjdk:jre
COPY --from=build ./somepath/app.jar .
CMD java app.jar
The first stage (defined by the first FROM) is only used to build the ".jar", the second stage will only contain the JRE and the ".jar" copied from the first stage.
- dashwav 7y agoAnything after Java 9 would have to use the jlink method, as with the new modules system, there is no longer a distinction between the JDK and JRE. The problem is most 3rd party libraries aren't ready for the modules switchover, so for anyone using those libraries, you are stuck with having either a 3-400mb docker image or using jlink
- javagram 7y agoThere are “jre” images for java 10 plus that exclude the java compiler and other unnecessary JDK components, you don’t need to use modules to use this.
- sgt 7y agoSorry, I didn't intend to write "image", but rather container. I can no longer edit my comment.