How to change the java version in docker image or container?

5/17/2021

In my spring boot microservice project, one of the microservice is upgraded to java 11 and it is causing some issue in my existing functionality. I want to change the version of java from 11 to 8 in that microservice. but I am unable to do it as its created as docker image automatically through jenkins.

In the Gradle file I have mentioned the java version as 1.8 but still somehow in the kubernetes cluster only for this particular service java is upgraded to 11.

confirmed the version of java by using following command in the server. "docker exec {container_id} java -version"

please suggest me how I can change the version of java in docker image or containers?

Is it possible to change the java version just by running linux command? or is it require to follow some other steps?

-- Rakshith M
docker
java
jenkins
kubernetes
openshift

1 Answer

5/18/2021

@RakshithM yes, Jenkins must refer the Dockerfile to build docker container, if you find out then you can do it as suggested by @David. for you reference https://docs.docker.com/language/java/build-images/ , any container refer to the base image which has the basic environment on which our application runs which basically starts with FROM in docker file. eg:

FROM openjdk:16-alpine3.13

here our container is referring to the openjdk:16 image which is minimal linux environment with java 16 on the top of which other tools are included which is defined in dockerfile. so in your case if you find the Dockerfile then you can change it to the java version of your need.

-- msucil
Source: StackOverflow