Introduce multistage Docker build for optimized image size
Implemented a multistage Docker build, separating build and runtime stages to reduce the final image size and improve security. Adjusted `.dockerignore` to exclude unnecessary files from the build context and updated the base JRE image to use the build output efficiently.
This commit is contained in:
1 parent
d0ea0535e2
commit
dad2e0356e
2 files changed
+14
-10
No files matched your search
+1
-8
@@ -1,15 +1,8 @@
|
|||||||
.git
|
.git
|
||||||
.github
|
.github
|
||||||
.idea
|
.idea
|
||||||
.mvn
|
|
||||||
src
|
|
||||||
classes
|
classes
|
||||||
logs
|
logs
|
||||||
target/*
|
target
|
||||||
!target/netneutrality.jar
|
|
||||||
*.iml
|
*.iml
|
||||||
README.md
|
README.md
|
||||||
checkstyle.xml
|
|
||||||
mvnw
|
|
||||||
mvnw.cmd
|
|
||||||
pom.xml
|
|
||||||
+13
-2
@@ -1,3 +1,14 @@
|
|||||||
|
FROM eclipse-temurin:25-jdk AS build
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
COPY .mvn .mvn
|
||||||
|
COPY mvnw pom.xml checkstyle.xml ./
|
||||||
|
RUN chmod +x mvnw && ./mvnw -B -q dependency:go-offline
|
||||||
|
|
||||||
|
COPY src src
|
||||||
|
RUN ./mvnw -B -q package -DskipTests
|
||||||
|
|
||||||
FROM eclipse-temurin:25-jre@sha256:ff82c74a630c08b417502c4c18189e62074edbb28eb1f2d31b799ac138c01058
|
FROM eclipse-temurin:25-jre@sha256:ff82c74a630c08b417502c4c18189e62074edbb28eb1f2d31b799ac138c01058
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd curl && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd curl && rm -rf /var/lib/apt/lists/*
|
||||||
@@ -8,7 +19,7 @@ ARG API_PORT=9000
|
|||||||
EXPOSE ${API_PORT}
|
EXPOSE ${API_PORT}
|
||||||
|
|
||||||
COPY startup.sh ./
|
COPY startup.sh ./
|
||||||
COPY target/netneutrality.jar ./
|
COPY --from=build /build/target/netneutrality.jar ./
|
||||||
|
|
||||||
RUN ["chmod", "+x", "./startup.sh"]
|
RUN ["chmod", "+x", "./startup.sh"]
|
||||||
CMD ["./startup.sh"]
|
CMD ["./startup.sh"]
|
||||||
Reference in new issue
Block a user