Skip to content

Commit 8b6432d

Browse files
committed
Optimize java-worker image
This patch optimizes the java-worker image; - Use multi-stage build to separate the build-stage from the "deploy" stage - Switch to the official Maven image, instead of manual installation of Maven. The official Maven image is also based on the `openjdk` repository on Docker Hub, which replaces the (now deprecated) `java` repository. - Use `COPY` instead of `ADD` to follow best-practice - Add `-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap` arguments so that JAVA will take memory-limits into account - Use a JRE base image for the final build-stage This change brings the size of the final image down from 184MB to 87MB Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 762543a commit 8b6432d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

worker/Dockerfile.j

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
FROM java:openjdk-8-jdk-alpine
2-
3-
RUN MAVEN_VERSION=3.3.3 \
4-
&& cd /usr/share \
5-
&& wget http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz -O - | tar xzf - \
6-
&& mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \
7-
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
1+
FROM maven:3.5-jdk-8-alpine AS build
82

93
WORKDIR /code
104

11-
ADD pom.xml /code/pom.xml
5+
COPY pom.xml /code/pom.xml
126
RUN ["mvn", "dependency:resolve"]
137
RUN ["mvn", "verify"]
148

159
# Adding source, compile and package into a fat jar
16-
ADD src/main /code/src/main
10+
COPY ["src/main", "/code/src/main"]
1711
RUN ["mvn", "package"]
1812

19-
CMD ["java", "-jar", "target/worker-jar-with-dependencies.jar"]
13+
FROM openjdk:8-jre-alpine
14+
15+
COPY --from=build /code/target/worker-jar-with-dependencies.jar /
16+
17+
CMD ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-jar", "/worker-jar-with-dependencies.jar"]

0 commit comments

Comments
 (0)