This Spring Boot application help you understand how we reduce the size of image of applications while deploying on Docker using jdeps and jlink.
- jdeps is responsible for analysing a JAR, with its dependencies, and identifying the parts of the JVM needed to run the application.
- It can out put this to a text file, which can be used by jlink.
- jdeps applicationname.jar or jdeps -verbose:package applicationname.jar
- jdeps -verbose:class applicationname.jar
- jdeps -profile applicationname.jar
- jdeps -dotoutput . -verbose applicationname.jar
- jdeps -s applicationname.jar or jdeps -summary applicationname.jar
- jlink takes a list of JVM modules, and builds a custom JVM with only those parts present.
- Depending upon our application, this can cut out massive parts of the runtime, reducing our overall Docker image size.
- First download java into the system
- set JAVA_HOME path
- set PATH="$PATH:$JAVA_HOME/bin"
- copy jar into target machine
- run jdeps command to identify the dependencies and write into file
- run jlink command to create custom jre with those modules that are written by jdeps command
- set JAVA_HOME path to the custom jre
- set PATH="$PATH:$JAVA_HOME/bin"
- expose spring boot app into a particular port number and give entry point to run the application.
docker build -f Dockerfile -t applicationname.jar
docker run -p 8085:8085 applicationname.jar