Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakaneroztekin/02ce630e42c1f8f93977e04a87ed3ec1 to your computer and use it in GitHub Desktop.
Save hakaneroztekin/02ce630e42c1f8f93977e04a87ed3ec1 to your computer and use it in GitHub Desktop.
spring-app-multi-stage [docker in a nutshell]
### BUILD ###
# use maven as base image
FROM maven:3.8.3-openjdk-16 AS build
# copy code to container directory (/home/app/src)
COPY /src /home/app/src
# copy pom to container directory (/home/app)
COPY pom.xml /home/app
# generate jar file
RUN mvn -f home/app/pom.xml clean package
# -------------------------------------------- #
### PACKAGE ###
# use openjdk as a base image
FROM openjdk:16
# create a new directory named app
RUN mkdir app
# copy jar from the Build stage to container directory (/app)
COPY --from=build /home/app/target/spring-app.jar /app
# make app the default directory for the upcoming commands
WORKDIR /app
# expose port 8080
EXPOSE 8080
# when container boots up, execute: java -jar spring-app.jar
ENTRYPOINT ["java", "-jar", "spring-app.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment