Why I am getting two different Java version given same docker tag is mentioned?

4/15/2021

My Dockerfile

FROM maven:3.5-jdk-8 AS build  
COPY src /usr/src/app/src  
COPY pom.xml /usr/src/app  
RUN mvn -f /usr/src/app/pom.xml clean package

FROM gcr.io/distroless/java:debug

COPY --from=build /usr/src/app/target /usr/app/target
COPY --from=build /usr/src/app/src /usr/app/src
EXPOSE 8080
ENTRYPOINT ["java", "-cp", "/usr/app/target/classes:/usr/app/target/dependency-jars/*", "com.salesforce.Main"]  

Local MacBook Docker container java version

openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

Kubernetes Pod java version

openjdk 11.0.9.1 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed mode)

Rationale: My understanding of the Docker container means that if we specify the same docker tag we should be able to get the same version of Java both in Local Mac and K8s Cluster. But I didn't get it.

Does anybody have a logical explanation of this behaviour?

-- Dinesh
docker
java
kubernetes

1 Answer

4/16/2021

The base image you are using gcr.io/distroless/java:debug, seems to be updated 3 days ago and the tag debug won't guarantee the same java version if there are updates in b/w the time you pulled it on your machine and in the container.

In order to ensure java version, use a versioned debug tag e.g gcr.io/distroless/java:8-debug for Java 8 or gcr.io/distroless/java:11-debug for Java 11

-- Hazim
Source: StackOverflow