78

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.

David Geary
  • 1,756
  • 2
  • 14
  • 23
  • 10
    See this github issue: https://github.com/docker-library/openjdk/issues/468 Upstream no longer provides a JRE, so no official JRE images will be produced. There is a similar discussion about [Adoptium (formerly AdoptOpenJDK) no longer releasing JREs](https://github.com/adoptium/temurin-build/issues/2683). For better or worse, official JREs are going the way of the Dodo. – Joachim Sauer Oct 11 '21 at 11:10
  • 1
    That being said, it seems the jdk now comes with tools to produce custom JREs, so it should be possible to create one on your own: https://www.baeldung.com/jlink and here an example from Eclipse Tamurin for a openjdk 11 JRE: https://hub.docker.com/_/eclipse-temurin https://blog.adoptium.net/2021/08/using-jlink-in-dockerfiles/ – kutschkem Oct 11 '21 at 11:21
  • 4
    @kutschkem: yes, custom jlink-built base images are the alternative, but I wouldn't call those "JREs", because that's not exactly what they are and calling them that can lead to assumptions that aren't right and to confusion. – Joachim Sauer Oct 11 '21 at 11:23
  • You can use [Alpine JDK 17](https://hub.docker.com/layers/openjdk/library/openjdk/17-alpine/images/sha256-a996cdcc040704ec6badaf5fecf1e144c096e00231a29188596c784bcf858d05?context=explore) `FROM openjdk:17-alpine` – CᴴᴀZ Aug 18 '22 at 07:41

7 Answers7

53

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
Santanu
  • 691
  • 3
  • 5
  • 3
    17-oracle is the same tag for 17.0.1-jdk-oraclelinux8, jdk-oraclelinux8, 17.0.1-jdk-oracle, 17-jdk-oracle, 17-oracle, jdk-oracle, etc. Basically it is the same JDK image, not JRE. https://github.com/docker-library/docs/blob/master/openjdk/README.md#simple-tags – igor Jan 14 '22 at 08:49
  • 4
    Doesn't this have licensing concerns? Most people want to avoid Oracle these day I would think – Novaterata Apr 18 '22 at 16:38
  • 5
    @Novaterata from Java 17 onwards, you can use it freely even for commercial purposes – Deekshith Anand May 16 '22 at 09:13
  • @DeekshithAnand – Novaterata May 16 '22 at 16:02
  • 3
    as @DeekshithAnand perfectly mentioned from Java 17 onwards, oracle image can be used freely. If you are looking for a different image then - "openjdk:17-jdk-slim" also works fine to create a lightweight image – Santanu Aug 22 '22 at 06:15
13

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

11

(As of 2023) Do not use any openjdk:17- images, because what you may get are old early jdk 17 builds with security issues !
On https://hub.docker.com/_/openjdk there is clear

DEPRECATION NOTICE

openJDK 17 is not build anymore!
(and not maintained in https://github.com/docker-library/openjdk)


While it was simpler before to use whatever linux flavour, now you need to make choice as different openJDK builds docker images will use different linux flavours.

E.g. amazoncorreto - Amazon Linux,
Oracle JDK - Oracle Linux etc


Different sources may recommend differently

E.g. on https://docs.docker.com/language/java/build-images/ uses eclipse-temurin

FROM eclipse-temurin:17-jdk-jammy

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
8

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

ChamaraL
  • 351
  • 4
  • 7
5

Adding to @PaulVerest's excellent answer, for the benefit of other newbies like me, I am posting here the Dockerfile that works for me (as of May 2023, built and run from a Windows 10 PC):

FROM amazoncorretto:17.0.7-alpine

# Add app user
ARG APPLICATION_USER=appuser
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER

# Configure working directory
RUN mkdir /app && \
    chown -R $APPLICATION_USER /app

USER 1000

COPY --chown=1000:1000 ./myapp-0.0.1-SNAPSHOT.jar /app/app.jar
WORKDIR /app

EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "/app/app.jar" ]

If you built your container using:

docker build -t docker_myapp .

Then, run it from the command line using:

docker run -p 8080:8080 docker_myapp

Note: You can't stop it from the same command line using Ctrl+C. To stop it, you need to open another command line and do:

docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED       STATUS       PORTS                    NAMES
16dad8047672   docker_myapp   "java -jar /app/app.…"   7 hours ago   Up 7 hours   0.0.0.0:8080->8080/tcp   sharp_rode

Then:

docker stop 16dad8047672   
Introspective
  • 554
  • 2
  • 5
  • 13
3

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.

David Geary
  • 1,756
  • 2
  • 14
  • 23
2

In your Dockerfile link:

FROM openjdk:17-alpine
belem
  • 341
  • 4
  • 3