I use Docker with a Java application, previously I used Java 8 JRE and my total docker image size was 163MB, I then moved to use Java 11 JRE and size increased to 230MB, I would prefer not to increase the size if possible.
But Java 11 allows you to build your own JRE (using jlink
from the JDK) containing only the modules you need. So I modified my DockerFile to be based on a JDK rather than JRE, I then used this to build the JRE with only the modules I needed and created this within my application folder. I then used rm -fr /opt/java
to remove the JDK as I no longer need it, assuming this would shrink the image size down, but it doesn't the image is now 553MB. My Applications runs but there is no point using jlink
if I cannot shrink the image down in size, what am I doing wrong ?
Docker File below:
FROM adoptopenjdk/openjdk11:alpine
RUN apk --no-cache add \
ca-certificates \
curl \
fontconfig \
msttcorefonts-installer \
tini \
&& update-ms-fonts \
&& fc-cache -f
RUN mkdir -p /opt \
&& curl http://www.jthink.net/songkong/downloads/build1114/songkong-linux-docker.tgz?val=130| tar -C /opt -xzf - \
&& find /opt/songkong -perm /u+x -type f -print0 | xargs -0 chmod a+x
RUN /opt/java/openjdk/bin/jlink --module-path=/opt/java/openjdk/jmods \
--add-modules java.desktop,java.datatransfer,java.logging,java.management,java.naming,java.net.http,java.prefs,java.scripting,java.sql,jdk.management,jdk.unsupported,jdk.scripting.nashorn \
--output /opt/songkong/jre
RUN rm -fr /opt/java
EXPOSE 4567
ENTRYPOINT ["/sbin/tini"]
# Config, License, Logs, Reports and Internal Database
VOLUME /songkong
# Music folder should be mounted here
VOLUME /music
WORKDIR /opt/songkong
CMD /opt/songkong/songkongremote.sh