Skip to content

Instantly share code, notes, and snippets.

@javajack
Forked from jakubigla/Dockerfile
Last active April 16, 2023 12:33
Show Gist options
  • Save javajack/60acc3650441e103a66336ed46b46b5d to your computer and use it in GitHub Desktop.
Save javajack/60acc3650441e103a66336ed46b46b5d to your computer and use it in GitHub Desktop.
Dockerfile for multistage build of spring boot application using maven with SonarQube and proxy support https://blog.pavelsklenar.com/spring-boot-run-and-build-in-docker/
### BUILD image
FROM maven:3-jdk-11 as builder
#Copy Custom Maven settings
#COPY settings.xml /root/.m2/
# create app folder for sources
RUN mkdir -p /build
WORKDIR /build
COPY pom.xml /build
#Download all required dependencies into one layer
RUN mvn -B dependency:resolve dependency:resolve-plugins
#RUN mvn dependency:resolve-plugins
#Copy source code
COPY src /build/src
# Build application
RUN mvn package
FROM openjdk:11-slim as runtime
EXPOSE 8080
#Set app home folder
ENV APP_HOME /app
#Possibility to set JVM options (https://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html)
ENV JAVA_OPTS=""
#Create base app folder
RUN mkdir $APP_HOME
#Create folder to save configuration files
RUN mkdir $APP_HOME/config
#Create folder with application logs
RUN mkdir $APP_HOME/log
VOLUME $APP_HOME/log
VOLUME $APP_HOME/config
WORKDIR $APP_HOME
#Copy executable jar file from the builder image
COPY --from=builder /build/target/*.jar app.jar
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ]
#Second option using shell form:
#ENTRYPOINT exec java $JAVA_OPTS -jar app.jar $0 $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment