Video in progress
Why is it recommended to base the image for a Java application on a JRE rather than a JDK?
A running application does not need the compiler or dev tools. A JRE image is much smaller, pulls faster, and has fewer packages in which a vulnerability could be found.
📖 Answer
The numbers are approximate, but the difference is noticeable: eclipse-temurin:21-jdk is around 400 MB, and 21-jre is nearly half that. On every deploy, the image is pulled from the registry to every node, so a smaller image comes up faster.
The second reason is security. The more there is inside the image, the more CVEs the scanner finds, and the more tools an attacker has if they get into the container.
One catch: a JRE may not include diagnostic utilities such as jcmd and jmap. If you might need a thread dump in prod, plan for it ahead of time. For example, keep a separate debug image, or attach a container with a JDK next to the pod using kubectl debug.
The JDK image is only needed at the build stage (Maven/Gradle compile there). That is why, in a multi-stage build, the first stage uses the JDK and the last one uses the JRE.
Sign up to mark studied questions and save your progress.