FROM adoptopenjdk/openjdk11:alpine AS buildĮNV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' I found article explained things quite I had one issue the base alpine:3.11 image cannot run Java out of the box, I nabbed a line from a doptopenjdk/openjdk11:alpine-jre to install various additional packages but I dont know which ones are needed to just run java with provided jre so I have probably installed to much. What I need to do is multi-stage builds instead whereby I build my jre in one stage, and then in a second stage based on base image without the jdk I can just copy the jre I created in the first stage into the second stage Since /opt/java is create as part of the base layer it will always exist in the image, even if I delete it in a later layer. Ive done some reading and now understand that each layer is built on top of other layer. The second stage import the JRE and add your code on itĮach stage have different base image, so the second one could use a small base image: # First stage - Create the JREįROM adoptopenjdk/openjdk11:alpine AS jreĬOPY -from=jre /opt/songkong/jre /opt/songkong/jreįor more information about multi-stage build: įor more information about image and layers: If you want to reduce the size, you will need to do a multiple stage build: You can visualize it by running docker image history myimage, you will have a list of layers and their size. In your case, we will reduce your image to 3 layer for the demonstration: īut, in fine, your image have the 3 layers with all the data. So when a file is created in one layer and deleted in an another layer, the file still exist, but no more available and most instruction in a Dockerfile create a new layer. It's normal by the nature of a docker image.Ī Docker image is base on multiple layer that stack together and each layer are immutable (could not update an another layer content). # Config, License, Logs, Reports and Internal Database add-modules sktop,java.datatransfer,java.logging,java.management,java.naming,java.prefs,java.scripting,java.sql,jdk.management,jdk.unsupported, \ RUN /opt/java/openjdk/bin/jlink -module-path=/opt/java/openjdk/jmods \ & find /opt/songkong -perm /u+x -type f -print0 | xargs -0 chmod a+x My Applications runs but there is no point using jlink if I cannot shrink the image down in size, what am I doing wrong ?ĭocker File below: FROM adoptopenjdk/openjdk11:alpine 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. 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 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.īut Java 11 allows you to build your own JRE (using jlink from the JDK) containing only the modules you need.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |