Created
May 3, 2020 17:35
-
-
Save dvsingh9/d3921de33a7a4303ffd66f7940771b50 to your computer and use it in GitHub Desktop.
Spring boot ultra slim (less than 90 mb) docker build script
This file contains hidden or 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
# (1) use Alpine Linux for build stage | |
FROM alpine:3.11.3 as build | |
# (2) install build dependencies | |
RUN apk --no-cache add openjdk11 | |
RUN apk --no-cache add maven | |
# build JDK with less modules | |
RUN /usr/lib/jvm/default-jvm/bin/jlink \ | |
--compress=2 \ | |
--module-path /usr/lib/jvm/default-jvm/jmods \ | |
--add-modules java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument \ | |
--output /jdk-minimal | |
# fetch maven dependencies | |
WORKDIR /build | |
COPY pom.xml pom.xml | |
RUN mvn dependency:go-offline | |
# build | |
COPY src src | |
RUN mvn clean package | |
# prepare a fresh Alpine Linux with JDK | |
FROM alpine:3.11.3 | |
# get result from build stage | |
COPY --from=build /build/target/*.jar /app.jar | |
COPY --from=build /jdk-minimal /opt/jdk/ | |
VOLUME /tmp | |
EXPOSE 8092 | |
CMD /opt/jdk/bin/java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've had to include java.rmi as well in my case, using spring-boot and joinfaces. Thank you!