I’m trying to dockerize a spring boot app but i’m having trouble building a jar file with maven.
I Already tried to follow this tutorial but somehow my .jar isn’t being updated by the ‘mvn package’ command inside the Dockerfile.
If I manually run ‘mvn package’ and then build the image, it works.
this is my dockerfile
FROM openjdk:11
FROM maven:3.8-jdk-11 as maven_build
COPY pom.xml pom.xml
COPY src src
RUN mvn clean package
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
my project structure
Demo
└── src
| ├── main
| │ ├── java
| │ └── com
| │ └── App.java
| │
| │
| └── test
|
├──── Dockerfile
├──── pom.xml
2
Answers
turns out that you can just skip the Dockerfile Altogether in this case and use this maven command instead:
and it will build a docker image for you
You need to use –from to copy an artifact built in the previous stage to the current stage.
Just replace
with