sebamed
sebamed

Reputation: 1077

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

WORKDIR /app

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:

[...]
  api:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - mysql-db
    ports: 
      - "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...

Upvotes: 0

Views: 2440

Answers (1)

sebamed
sebamed

Reputation: 1077

The problem was with my docker client installation. It somehow did not setup necessary permissions after installation. On other machines, this Dockerfile works fine.

Well, this was a lesson for some future times.

Upvotes: 1

Related Questions