Build jar inside dockerized staged build

This commit is contained in:
Martin Moravek 2020-07-21 20:36:52 +02:00
parent 02815065d7
commit f6b7ed46a6
2 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,13 @@
# Base image with maven installed already
FROM maven:3.6.3-jdk-8 as builder
# Copy whole project inside docker
COPY . .
# Build project
RUN mvn clean package
# Base image containing OpenJDK 8, maintained by RedHat
FROM adoptopenjdk:8-jre-hotspot
@ -23,8 +33,9 @@ USER $USER
# Symlink to java executable to make it available to sudo user
RUN sudo ln -s $JAVA_HOME/bin/java /usr/bin/java
# Copy jar from target to working directory
COPY target/*.jar /ward.jar
# Copy jar and pom from builder image to working directory
COPY --from=builder target/*.jar /ward.jar
COPY --from=builder pom.xml /pom.xml
EXPOSE 4000

View File

@ -129,7 +129,7 @@ Ward works nice on all popular operating systems, because it uses [OSHI](https:/
Build for Docker
1. Clone the project
2. mvn clean package
3. docker build --tag ward .
4. docker run --rm -it --name ward -p 4000:4000 -p <application port>:<application port> --privileged ward
5. Go to localhost:4000 in web browser, input the same application port
2. docker build --tag ward .
3. docker run --rm -it --name ward -p 4000:4000 -p <application port>:<application port> --privileged ward
4. Go to localhost:4000 in web browser, input the same application port
5. If you get error after being redirected to application port try hitting refresh.