I created a web application using Springboot and now I'm going to dockerize it and upload it into docker hub. So my Dockerfile
is,
FROM openjdk:8
EXPOSE 8080
ADD target/spring-boot-web-0.0.1-SNAPSHOT.jar spring-boot-web-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","spring-boot-web-0.0.1-SNAPSHOT.jar"]
After creating .jar
inside my target I'm building docker image using the following command,
docker build -t kubernatesimage
It builds the docker image successfully and when I run the docker images
I can see the created image. But before uploading it into docker hub I need to run and check so I'm executing,
docker run -it -p 4000:80 kubernatesimage
And this returns the following exception,
Exception in thread "main" java.lang.UnsupportedClassVersionError: guru/springframework/SpringBootWebApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
According to @Nithin's answer in this StackOverflow question, I found this happens due to version missmatch and the java version codes,
49 = Java 5
50 = Java 6
51 = Java 7
52 = Java 8
53 = Java 9
54 = Java 10
55 = Java 11
56 = Java 12
57 = Java 13
58 = Java 14
But still, I have no idea what do I need to perform to solve the issue. I mentioned openjdk:8 in my Dockerfile
and I run java -version
to get the local JDK version and it returned
java version "1.8.0_271"
So do I need to change java version in my local machine or change my Dockerfile
?