Adoptium Summit 2025 - CFP is Open!

Join us Virtually on Wednesday, October 01st 13-15 CEST and showcase your innovative work with Adoptium technologies to your industry peers!

News article

Using Jlink in Dockerfiles instead of a JRE

How to swap a JRE docker image for a jlink runtime

The Eclipse Temurin project is excited to announce that the official docker images for Temurin binaries are now available on Docker Hub.

If you were previously using an AdoptOpenJDK JDK image with Ubuntu Focal or CentOS 7 as the base and wish to continue using the Temurin JDK image on the same base, the migration path is very simple. Simply change adoptopenjdk to eclipse-temurin and set the distro after the version number in the tag. E.g for Ubuntu Focal and an application called japp.jar you might write:

FROM eclipse-temurin:11-focal
# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]

If you were using a base image that was not Ubuntu Focal or CentOS 7 you can use docker's COPY command to bring the JDK into your image. E.g to use a Temurin binary inside a Debian base image:

FROM debian
ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:11 $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"
# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]

What about JRE base images?

NOTE: This paragraph has been superceded since we are now shipping JREs with 17+ again including docker images - see https://adoptium.net/blog/2021/12/eclipse-temurin-jres-are-back/ for the details, however we still recommend using jlink to produce your own cut down java runtimes where possible

The Eclipse Temurin project produces JRE images for version 8. For JDK 11+ it is possible to use jlink and produce a custom runtime that works directly with your application:

# Example of custom Java runtime using jlink in a multi-stage container build
FROM eclipse-temurin:11 as jre-build

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
         --add-modules java.base \
         --strip-debug \
         --no-man-pages \
         --no-header-files \
         --compress=2 \
         --output /javaruntime

# Define your base image
FROM debian:buster-slim
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-build /javaruntime $JAVA_HOME

# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]

The --add-modules command accepts a comma seperated list of modules. To determine which modules you need you can run the following command with your existing JRE:

jdk-11.0.8+10-jre/bin/java --list-modules

We aren't completely ruling out creating JRE's for JDK11+ at this stage, so if a multi-stage dockerfile doesn't work for you then we want to hear your thoughts.

Related Articles

Explore more articles that might interest you based on your reading history.

blog banner image

Eclipse Temurin 8u452, 11.0.27, 17.0.15, 21.0.7 and 24.0.1 Available

April 29, 2025

Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u452, 11.0.27, 17.0.15, 21.0.7 and 24.0.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms...

blog banner image

Eclipse Temurin 24 Available

March 26, 2025

Adoptium is excited to announce the immediate availability of Eclipse Temurin 24.

blog banner image

Eclipse Temurin JDK 24.0.0+36 enables JEP 493

March 10, 2025

Eclipse Temurin enables JEP 493 for the JDK 24 general availability release (24.0.0+36) which significantly reduces the size of the JDK archive.

Thank you to our 300+ contributors