Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenJDK Java 17 docker image

We are upgrading our microservices in docker to use Java 17 and previously we used the base image openjdk:11-jre-slim. What is the corresponding image for Java 17?

There doesn't seem to be a openjdk:17-jre-slim? In fact there dont seem to be any recent jre images - just jdks. The 11-jre-slim image seems to be arount 75MB - is there a suitable similarly sized Java 17 image?

We have also used alpine images in the past too.

like image 245
David Geary Avatar asked Oct 11 '21 11:10

David Geary


People also ask

What is the OpenJDK Docker image based on?

openjdk:<version>-alpine This image is based on the popular Alpine Linux project, available in the alpine official image.

What is OpenJDK slim?

openjdk:<version>-slimIt only contains the minimal packages needed to run Java. Unless you are working in an environment where only the openjdk image will be deployed and you have space constraints, we highly recommend using the default image of this repository. Follow this answer to receive notifications.

What is OpenJDK?

OpenJDK is the official reference implementation of Java SE since version 7. Java is a registered trademark of Oracle and/or its affiliates. The most straightforward way to use this image is to use a Java container as both the build and runtime environment.

How do I start building Docker images with Java?

Work through the orientation and setup in Get started Part 1 to understand Docker concepts. Refer to the following section for Java prerequisites. Before we start building images, ensure you have enabled BuildKit on your machine. BuildKit allows you to build Docker images efficiently. For more information, see Building images with BuildKit.

Is it possible to build a JRE with Docker?

Before you could build a Docker image with a size of less than 80MB – this was easily achieve with a multi-stage Docker build. In the meantime the only choice for building a JRE is to use jlink. The Eclipse Foundation seems to be developing a JRE for Java 17 after a lot of feedback from the community.

Where do the OpenJDK binaries in the default image come from?

The OpenJDK binaries in the default image as well as the -oracle and -oraclelinux7 variants are built by Oracle and are sourced from the OpenJDK community. These binaries are licensed under the GPLv2 with the Classpath Exception. This image is based on the popular Alpine Linux project, available in the alpine official image.


Video Answer


5 Answers

Oracle image is freely available from Java-17 openjdk:17-oracle

Dockerfile:

FROM openjdk:17-oracle

openjdk:17-jdk-slim also creates lightweight image

Dockerfile:

FROM openjdk:17-jdk-slim
like image 56
Santanu Avatar answered Oct 27 '22 01:10

Santanu


You can try this (eclipse-temurin:17-jre-alpine) which is around 50MB of compressed size https://hub.docker.com/layers/eclipse-temurin/library/eclipse-temurin/17-jre-alpine/images/sha256-839f3208bfc22f17bf57391d5c91d51c627d032d6900a0475228b94e48a8f9b3?context=explore

I couldn't sill find an OpenJDK jre image

like image 27
Chamara Liyanage Avatar answered Oct 26 '22 23:10

Chamara Liyanage


If you are looking for the tiniest Docker images with Alpine Linux and OpenJDK, have a look at Liberica JDK containers at DockerHub https://hub.docker.com/r/bellsoft/liberica-openjdk-alpine The images have Alpine and Liberica Lite, which is optimized in size to be used on microservices. It is also recommended by the Spring team https://spring.io/quickstart

like image 5
Alexander Belokrylov Avatar answered Oct 27 '22 00:10

Alexander Belokrylov


An update on this - looking again at the Eclipse Adoptium issue mentioned above (https://github.com/adoptium/temurin-build/issues/2683) the more recent comments indicate they have now started producing JRE images.

We have switched to using eclipse-temurin:17-jre-focal. There is also a (slightly larger) 17-jre-centos7 and a smaller 17-jre-alpine, but we now need some libraries that aren't in alpine.

like image 3
David Geary Avatar answered Oct 26 '22 23:10

David Geary


In your Dockerfile link:

FROM openjdk:17-alpine
like image 1
belem Avatar answered Oct 27 '22 01:10

belem