Docker Improvements (#32)

* Build the application using the maven docker image (no longer need to compile the app locally).

Use the Amazon Corretto JDK distro for the JRE source.  (OpenJDK has been deprecated).  Create the small JRE using the jlink tool.

Using the alpine distro as base; copy the generated JRE; copy the built application.

* Add dockerignore and fix volume
This commit is contained in:
Issa Fram
2025-03-23 07:28:45 -04:00
committed by GitHub
parent deb9322be3
commit 728b346cd3
2 changed files with 41 additions and 5 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
README.md
LICENSE
target
docker-compose.yml
Jenkinsfile
Dockerfile
mvnw
mvnw.cmd

View File

@@ -1,11 +1,39 @@
FROM openjdk:21-jdk-slim
# Build the application using the maven image
FROM maven:3.9.9 AS builder
WORKDIR /build
COPY . .
RUN mvn clean package
# Create a slimmed version of the Java JRE using the Corretto image
FROM amazoncorretto:21.0.6-alpine AS corretto-jdk
RUN apk add --no-cache binutils
# Build small JRE image
RUN $JAVA_HOME/bin/jlink \
--verbose \
--add-modules ALL-MODULE-PATH \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=zip-4 \
--output /slim_jre
# Use a small Linux distro for final image
FROM alpine:latest
ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"
# Copy the JRE into Alpine image
COPY --from=corretto-jdk /slim_jre $JAVA_HOME
# Copy the compiled app into Alpine image
COPY --from=builder build/target/quickdrop-0.0.1-SNAPSHOT.jar app/quickdrop.jar
WORKDIR /app
COPY target/quickdrop-0.0.1-SNAPSHOT.jar /app/quickdrop.jar
VOLUME ["/app/db", "/app/log", "/files"]
VOLUME ["/app/db", "/app/log", "/app/files"]
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/quickdrop.jar"]
ENTRYPOINT ["java", "-jar", "/app/quickdrop.jar"]