Home > Blockchain >  Run docker contianer with Spring Boot App
Run docker contianer with Spring Boot App

Time:09-21

I have a problem with the spring boot app below, I need to contain a spring boot app to run it locally on mac, to do it I wrote the dockerfile shown below, the container image is generated correctly but when I put it in run I have the error below, what is it due to and what can this be? to do it all I use the shell file below,how do i fix the error?

Error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/reportserver/report/ReportApplication 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
        at java.lang.ClassLoader.defineClass1(Native Method)

docker.sh:

#!/bin/bash
#define docker name
dockername=quote
#Delete all containers and all volumes
docker system prune -a
#Build of container and image
docker build -t $dockername .
#Run container
docker run --publish 8081:8081 $dockername

Dockerfile:

FROM openjdk:alpine
EXPOSE 8081
ARG JAR_FILE=target/report-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

CodePudding user response:

you are using and older jvm version in your docker base image openjdk:alpine java 8 I guess and you need to use java 11 at least, use this tag openjdk:11.0.12-jre instead or search for the equivalente alpine version.

Here is a list of java versions and their class version numbers List of Java class file format major version numbers?

CodePudding user response:

Looks like you are using java 11 to build the jar file in your system.

In your docker file, it is using java 8 to run the jar.

Instead do this to your Dockerfile.

FROM openjdk:11-slim
EXPOSE 8081
ARG JAR_FILE=target/report-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

From the official github docs, openjdk still doesnot fully support alpine as a base OS. "-slim" version will use debian instead.

The OpenJDK port for Alpine is not in a supported release by OpenJDK, since it is not in the mainline code base. It is only available as early access builds of OpenJDK Project Portola. See also this comment. So this image follows what is available from the OpenJDK project's maintainers.

You can go through the list of tags and their details at the below link.

https://github.com/docker-library/docs/blob/master/openjdk/README.md#supported-tags-and-respective-dockerfile-links

  • Related