We do. As of this pr, you can use distroless with your own jlink + spring boot.
FROM openjdk:jdk-buster as jreBuilder
RUN jlink \
--add-modules jdk.unsupported,java.sql,java.desktop,java.naming,java.management,java.instrument,java.security.jgss,java.rmi \
--verbose \
--strip-debug \
--compress 2 \
--no-header-files \
--no-man-pages \
--output /jre
FROM gcr.io/distroless/java-debian10:base
ARG JAR_FILE
COPY --from=jreBuilder /jre /usr/lib/jre
ENTRYPOINT ["/usr/lib/jre/bin/java", "-jar", "./app.jar"]
COPY ./target/${JAR_FILE} ./app.jar
If you're using modules already, you won't need to specify all those modules manually. Also the base image could be extracted out, or you could let docker cache the layer for you.
java:base is necessary because there are a few libraries that aren't repackaged by jlink like libz or image libs. Although that would be neat, jlink being native library aware. The tool could know if you have a dependency on java.desktop, which would then have a dependency on libpng and libjpeg. /u/pron98 do you know if there is any tooling around associating native libraries with the java modules that require them?
afaik libz is required at startup by the jvm, other ones like libjpeg are only necessary when the imageio libraries are called.
here's the full list of libraries required by java, on top of the onces from base.
13
u/uncont Mar 12 '21
We do. As of this pr, you can use distroless with your own jlink + spring boot.
If you're using modules already, you won't need to specify all those modules manually. Also the base image could be extracted out, or you could let docker cache the layer for you.