Skip to content

Commit

Permalink
improve: use jlink to reduce jdk size in the image (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Jul 3, 2024
1 parent 243b085 commit 123316b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
# under the License.
#

FROM eclipse-temurin:17 as jre-build

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules ALL-MODULE-PATH \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

RUN echo networkaddress.cache.ttl=1 >> /javaruntime/conf/security/java.security
RUN echo networkaddress.cache.negative.ttl=1 >> /javaruntime/conf/security/java.security

FROM ubuntu:22.04
MAINTAINER Apache BookKeeper <dev@bookkeeper.apache.org>

Expand All @@ -42,7 +56,6 @@ RUN set -x \
&& adduser "${BK_USER}" \
&& apt-get update \
&& apt-get install -y ca-certificates apt-transport-https \
&& apt-get install -y --no-install-recommends openjdk-17-jdk \
&& apt-get install -y --no-install-recommends python3 pip \
&& ln -s /usr/bin/python3 /usr/bin/python \
&& apt-get install -y --no-install-recommends gpg gpg-agent wget sudo \
Expand All @@ -66,10 +79,9 @@ RUN set -x \

WORKDIR /opt/bookkeeper

ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-$TARGETARCH

RUN echo networkaddress.cache.ttl=1 >> $JAVA_HOME/conf/security/java.security \
&& echo networkaddress.cache.negative.ttl=1 >> $JAVA_HOME/conf/security/java.security
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH="$PATH:$JAVA_HOME/bin"
COPY --from=jre-build /javaruntime $JAVA_HOME

COPY scripts /opt/bookkeeper/scripts
RUN chmod +x -R /opt/bookkeeper/scripts/
Expand Down

0 comments on commit 123316b

Please sign in to comment.