Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JRE version with jib (Docker)

Tags:

java

docker

jib

I'm trying to get my head around building Docker images with Google's Jib project and Jib Maven Plugin.

I don't understand how to specify the JRE version.

I understand I can customize in the plugin's config, something like:

<configuration>
  <from>
    <image>gcr.io/distroless/java</image>
  </from>
</configuration>

but what does that mean in terms of the actual JRE version which will be used ? What if I want say specifically JRE 8u172 ?

The Jib project states this as a feature:

Reproducible - Rebuilding your container image with the same contents always generates the same image.

therefore I'm assuming there must be some way to lock down the JRE version?

Level: Advanced on Java and Maven, newbie on everything Docker.

like image 343
peterh Avatar asked May 05 '19 11:05

peterh


People also ask

Does Docker support Java 11?

Controllers use Java 11 by default If you are running one of the Jenkins Docker controller images that does not include a JDK version in its label, the Java runtime will switch from Java 8 to Java 11 with the upgrade. For example: Jenkins 2.306 running as jenkins/jenkins:latest uses Java 8.

Does jib use Docker?

Jib builds containers without using a Dockerfile or requiring a Docker installation. You can use Jib in the Jib plugins for Maven or Gradle, or you can use the Jib Java library.

Does Docker need JDK?

Use a JRE, not a JDK When creating a Docker image, we should only assign the necessary resources to function correctly. This means that we should start by using an appropriate Java Runtime Environment (JRE) for your production image and not the complete Java Development Kit (JDK).

What is jib Maven plugin?

Jib is a set of plugins for Maven and Gradle for building optimized OCI-compliant container images for Java applications without a Docker daemon.


2 Answers

Availability of 8u172 depends on whether the distributor has created a build image of that version.

java building version is not managed with docker image tags with gcr.io/distroless/java.
Currently gcr.io/distroless/java:8, it was 8u212 as below.

https://console.cloud.google.com/gcr/images/distroless/GLOBAL/java?gcrImageListsize=30

~ $ docker run -it --rm  --entrypoint java  gcr.io/distroless/java:8 -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
~ $

If you want to specify to java build version, I suggest using AdroptOpenJDK.

e.g.

<configuration>
  <from>
    <image>adoptopenjdk/openjdk8:jdk8u172-b11</image>
  </from>
</configuration>

If you can use 8u171, you can select openjdk.

<configuration>
  <from>
    <image>openjdk:8u171-jre</image>
  </from>
</configuration>

  • https://hub.docker.com/r/adoptopenjdk/openjdk8/tags
  • https://hub.docker.com/_/openjdk?tab=tags&page=4
like image 94
Hiroki Matsumoto Avatar answered Oct 18 '22 06:10

Hiroki Matsumoto


You probably want to use a base image with java preinstalled. every docker image contains tag(s), which are like versions. if you don't specify tag like you did above, then the latest is taken and that can lead to unexpected change of java version.

For example you can use opendjk image with java version 8u212 by using openjdk:8u212-jre-stretch. and in OpenJDK Docker Hub you can see the list of all available tags

like image 34
matanper Avatar answered Oct 18 '22 06:10

matanper