Home > Software engineering >  Understanding Startup Time Difference Between JRE and JDK Based Images
Understanding Startup Time Difference Between JRE and JDK Based Images

Time:07-28

I am struggling to understand the startup time difference between JRE based application and JDK based application.

Think that I have an application with sample DockerFile

# syntax=docker/dockerfile:experimental

ARG BASE_IMAGE_FROM=<image>
FROM $BASE_IMAGE_FROM/maven-jdk11:0.0.2 as builder

WORKDIR /builder
COPY settings.xml /settings.xml
COPY . .

RUN --mount=type=cache,id=m2-cache,target=/root/.m2 /root/build.sh <app-name>

## app
FROM $BASE_IMAGE_FROM/<jre-name>

ARG APP_PATH=/builder
ARG DEPENDENCY=${APP_PATH}/target/dependecy

WORKDIR /server

COPY <somethings>

USER <some-user>

# update class to run
ENTRYPOINT exec java ${JAVA_OPTS} -cp app/config:app/lib/setup.jar:app:app/lib/* <app-name>

In the FROM $BASE_IMAGE_FROM/ part of the file, I specify JDK based or JRE based image. The current application is based on java 11 alpine JDK image. I've changed it with JRE based image. There is a big difference in size of the images.

I also thought there should be improvements in the startup time because of the overhead of the JDK. Yet, the startup time didn't change. I couldn't figure it why.

Any opinions?

CodePudding user response:

Both the JDK and the JRE contain the same java runtime. The JDK contains additional tools like the javac compiler, javadoc documentation tool, and so on.

So in your setup, the JRE-based image will be much smaller, but when the container starts up, the ENTRYPOINT java ... starts the same JVM, loads the same class files, and runs the same application.

There's nothing different here other than the disk space required by the JDK functionality you're not using (if you need to pull the image, also the network I/O and time to download the unused files).

  • Related