简体   繁体   中英

Understanding Startup Time Difference Between JRE and JDK Based Images

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM