Reputation: 3520
I hava java application which needs to be dockerized now and I have 2 options.
FROM maven:3-jdk-11 as builder
COPY propel_settings_local.xml /root/.m2/settings.xml
RUN mkdir -p /build
ADD . /build/
WORKDIR /build
RUN mvn -B dependency:resolve dependency:resolve-plugins
RUN mvn clean install
Which is better approach among these two options?
Upvotes: 0
Views: 752
Reputation: 60104
Both options seems fine but I will say it totaly depend on your case but you can consider some of them below.
Build locally and add the jar generated at target folder to docker image.
Build it while creating the image.
Further, you can explore best practices and 7-best-practices-for-building-containers for your self.
Upvotes: 2
Reputation: 2160
I have springboot applications and have been following multi-stage build concept of docker
FROM maven:3-jdk-11 as builder
WORKDIR chooseTheOneYouWant
COPY . . ( i.e. copy whole of your code into the work directory)
RUN mvn -B package
FROM openjdk:8
RUN mkdir /usr/app
COPY --from=build .jarFile /usr/app
WORKDIR /usr/app
CMD ["java", "-jar", "/usr/app/.jarFile"]
Upvotes: 1