Multi-Stage Spring Boot Dockerization Using Maven

Trying to get the multi-stage Spring Boot application Dockerfile that works.

The idea is to:

  1. Build and package the project using mvn package command
  2. Run the built .jar file

After some research, I found this article. It provides complete Dockerfile, but it does not work for me.

I modified the initial Dockerfile, and now it looks like this:

FROM maven:3.6.2-jdk-8-slim AS MAVEN_BUILD

COPY pom.xml /build/
COPY src /build/src/

WORKDIR /build/

RUN mvn -Dmaven.test.skip=true package -Ptest # This line does not work properly

FROM openjdk:8-jre


COPY --from=MAVEN_BUILD /build/target/platform-0.0.1.jar /app/

ENTRYPOINT ["java", "-jar", "platform-0.0.1.jar"]

I created a docker-compose.yml that tries to build this Dockerfile:

      context: .
      dockerfile: Dockerfile
      - mysql-db
      - "8080:8085"

After running the docker-compose up --build -d command, I always get this error:
docker-compose log

Am I missing something?

Running the mvn -Dmaven.test.skip=true package -Ptest command in the actual project folder works normally…

Source: StackOverflow