-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile-optimized-dontwork
57 lines (50 loc) · 2.29 KB
/
Dockerfile-optimized-dontwork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#https://medium.com/hotels-com-technology/honey-i-shrank-the-java-image-9f737aef8963
#Works worse with this project than standard Dockerfile
# Image used to create the minimal java distribution
FROM debian:9.5-slim AS build
# Install wget to pull java binaries
RUN apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/*
# Download java and unpack it
ARG JAVA_DOWNLOAD_CHECKSUM=3784cfc4670f0d4c5482604c7c513beb1a92b005f569df9bf100e8bef6610f2e
RUN cd /opt; wget --no-check-certificate https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz && echo "${JAVA_DOWNLOAD_CHECKSUM} openjdk-11_linux-x64_bin.tar.gz" | sha256sum -c && tar zxf openjdk-11_linux-x64_bin.tar.gz && rm -f openjdk-11_linux-x64_bin.tar.gz
# Set java home and run jlink to create a minimal java distribution with modules required for Spring Boot
ENV JAVA_HOME=/opt/jdk-11
ENV PATH="$PATH:$JAVA_HOME/bin"
RUN jlink \
--module-path /opt/java/jmods \
--compress=2 \
--add-modules java.base,java.logging,java.desktop,java.naming \
--no-header-files \
--no-man-pages \
--output /opt/jdk-mini
# Start a new image and copy just the minimal java distribution from the previous one
FROM debian:9.5-slim
COPY --from=build /opt/jdk-mini /opt/jdk-mini
# Set our java home and other useful envs
ENV JAVA_HOME=/opt/jdk-mini
ENV PATH="$PATH:$JAVA_HOME/bin"
ENV DIRPATH /opt/app
# Create some dirs and copy app jar and libs
RUN mkdir -p $DIRPATH
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} $DIRPATH/app.jar
#COPY build/libs/app.jar $DIRPATH/
#COPY build/libs $DIRPATH/libs
RUN chmod 755 $DIRPATH/app.jar
WORKDIR $DIRPATH
CMD exec $JAVA_HOME/bin/java $JAVA_JVM_ARGS -jar app.jar
#FROM openjdk:8-jdk-alpine
#FROM alpine:3.10.1
#RUN apk --no-cache add openjdk11
# build JDK with less modules
#ARG JAVA_BIN=/usr/lib/jvm/default-jvm/bin/
#RUN ${JAVA_BIN}jlink\
# --compress=2\
# --module-path /usr/lib/jvm/default-jvm/jmods\
# --add-modules java.base,java.logging,java.desktop,java.naming\
# --output /jdk-minimal
# --add-modules java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument\
#COPY --from=build /jdk-minimal /opt/jdk/
#ARG JAR_FILE=build/libs/*.jar
#COPY ${JAR_FILE} app.jar
#ENTRYPOINT ["/jdk-minimal/bin/java","-jar","/app.jar"]