Sim
Sim

Reputation: 382

Docker multi-stage build not running all stages

I am trying to build an image from this Dockerfile:

FROM openjdk:14-slim-buster AS builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM openjdk:14-slim-buster
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/resources/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

The problem is it never reaches the second stage. I can see the total steps in the counter when the image is being built, but it just stops and executes this as a new container which is running the actual application

RUN java -Djarmode=layertools -jar application.jar extract

Upvotes: 1

Views: 1546

Answers (2)

Sim
Sim

Reputation: 382

To answer my own question, it was happening because of the Spring Boot version which was not ready to handle multistage builds, but after upgrading the service to 2.3.x i can build.

Upvotes: 1

Nann
Nann

Reputation: 1

I think it is because of the Jar file not in supported form. That's why jarmode can't process it. Jarmode is a special system used to extracting Layered Jars.

You can check out: https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1 for detail info.

Upvotes: 0

Related Questions