News article

Using Jlink in Dockerfiles instead of a JRE

The Eclipse Temurin project is excited to announce that the official docker images for Temurin binaries are now available on Docker Hub. If…
George Adams
George Adams, August 20, 2021

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
Eclipse Temurin offers high-performance, cross-platform, open-source Java runtime binaries that are enterprise-ready and Java SE TCK-tested for general use in the Java ecosystem.
blog banner image

Eclipse Temurin 8u432, 11.0.25, 17.0.13, 21.0.5 and 23.0.1 Available

November 04, 2024

Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u432-b06, 11.0.25+9, 17.0.13+11, 21.0.5+11 and 23.0.1+11. As…Read More
blog banner image

Eclipse Temurin 23 Available

September 20, 2024

Adoptium is happy to announce the immediate availability of Eclipse Temurin 23+37. As always, all binaries are thoroughly tested and…Read More
blog banner image

Eclipse Temurin Reproducible Verification Builds for Secure Supply Chain Validation

August 09, 2024

What is a third-party Reproducible Verification Build? A third-party reproducible verification build is a re-build of an official software…Read More

Thank you to our 300+contributors