Created
June 13, 2022 07:55
-
-
Save hakaneroztekin/02ce630e42c1f8f93977e04a87ed3ec1 to your computer and use it in GitHub Desktop.
spring-app-multi-stage [docker in a nutshell]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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