Skip to content

Instantly share code, notes, and snippets.

@dvsingh9
Created May 3, 2020 17:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dvsingh9/d3921de33a7a4303ffd66f7940771b50 to your computer and use it in GitHub Desktop.
Save dvsingh9/d3921de33a7a4303ffd66f7940771b50 to your computer and use it in GitHub Desktop.
Spring boot ultra slim (less than 90 mb) docker build script
# (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
@gilbertoca
Copy link

I've had to include java.rmi as well in my case, using spring-boot and joinfaces. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment