Skip to content

Commit 22d9c42

Browse files
committed
feat: optimize Docker image with custom JRE and minimal base
- Create custom JRE with jlink using only required modules - Use debian:bookworm-slim with security updates - Remove unnecessary files to reduce image size
1 parent a8d9207 commit 22d9c42

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

core/Dockerfile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
ARG ECLIPSE_TEMURIN_JRE=21-jre
2-
FROM eclipse-temurin:${ECLIPSE_TEMURIN_JRE}
1+
FROM eclipse-temurin:21 AS jre-build
2+
3+
# Create a custom Java runtime
4+
RUN $JAVA_HOME/bin/jlink \
5+
--add-modules java.base,java.compiler,java.desktop,java.management,java.naming,java.security.jgss,java.security.sasl,java.sql,jdk.unsupported \
6+
--strip-debug \
7+
--no-man-pages \
8+
--no-header-files \
9+
--compress=zip-6 \
10+
--output /javaruntime
11+
12+
# Define the base image
13+
FROM debian:bookworm-slim
14+
15+
ENV JAVA_HOME=/opt/java/openjdk
16+
ENV PATH="${JAVA_HOME}/bin:${PATH}"
17+
COPY --from=jre-build /javaruntime $JAVA_HOME
318

419
LABEL org.opencontainers.image.title="RESTHeart"
520
LABEL org.opencontainers.image.description="RESTHeart is Java Framework, built on top of Undertow"
@@ -14,8 +29,13 @@ LABEL maintainer="SoftInstigate <info@softinstigate.com>"
1429
# Reduce image size by removing package lists after installation
1530
RUN apt-get update && \
1631
apt-get upgrade -y && \
32+
apt-get install -y --no-install-recommends ca-certificates && \
33+
apt-get autoremove -y && \
1734
apt-get clean && \
18-
rm -rf /var/lib/apt/lists/*
35+
rm -rf /var/lib/apt/lists/* && \
36+
rm -rf /tmp/* && \
37+
rm -rf /var/tmp/* && \
38+
rm -rf /var/cache/apt/archives/*
1939

2040
WORKDIR /opt/restheart
2141

@@ -29,4 +49,5 @@ COPY target/plugins/lib/*.jar plugins/lib/
2949
ENV RHO='/mclient/connection-string->"mongodb://host.docker.internal";/http-listener/host->"0.0.0.0"'
3050

3151
ENTRYPOINT [ "java", "-Dfile.encoding=UTF-8", "-server", "-jar", "restheart.jar" ]
52+
3253
EXPOSE 8009 8080 4443

0 commit comments

Comments
 (0)