0

I have a spring boot application which contains a Main Class. I have Docker File as below:

FROM docker.io/openjdk:11-jre-slim
EXPOSE 8082
EXPOSE 8443
ADD target/base-application.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=prod -jar /app.jar

I am creating a Docker image by using this Docker file. Let's consider that this docker file is Docker1.

I have another Spring Boot application (which doesn't have a Main class) with Docker file as below:

FROM Docker1:0.0.1
EXPOSE 8443
ADD target/child-application.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=dev -jar /app.jar

I am using Docker1 as a base image for the docker image of 2nd application. When I am trying to run 2nd docker image, I am getting an error "no main manifest attribute, in /app.jar". Can you please help me to run the Main class of Docker1 by running 2nd Docker image?

Ajinkya Jagtap
  • 115
  • 1
  • 2
  • 10
  • Hi. Have you tried the solutions related at https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute ? – Sandro Athaide Dec 03 '19 at 12:51
  • In the second image, `/app.jar` is the jar file from the second stage, which as you say doesn't have a main class. The jar file from the first stage is overwritten by the second stage's `ADD` instruction. – David Maze Dec 03 '19 at 14:16
  • @SandroAthaide, I had already done the changes given on that link. The only part that I was missing is in the answer. – Ajinkya Jagtap Dec 03 '19 at 16:35

1 Answers1

1

So you want to run main class from target/base-application.jar file. Below line in Docker2 replaces base-application.jar with child-application.jar

ADD target/child-application.jar app.jar

To fix the issue you can modify your second Docker file as:

FROM Docker1:0.0.1
EXPOSE 8443
ADD target/child-application.jar child-application.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=dev -jar /app.jar
savas
  • 241
  • 2
  • 9