From d15fba6fd611e4e21e78999bc442ca1bfc847cd7 Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Thu, 7 Nov 2019 17:39:29 +0100 Subject: [PATCH] Improve Dockerfile example in deployment documentation Add stage build to unpack jar Change runtime base image by a jre-alpine Signed-off-by: Guillaume Lours --- .../src/main/asciidoc/deployment.adoc | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc index 2a9fe0227a1e..8f44f4765303 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc @@ -35,17 +35,23 @@ Once you have unpacked the jar file, you can also get an extra boost to startup More efficient container images can also be created by copying the dependencies to the image as a separate layer from the application classes and resources (which normally change more frequently). There is more than one way to achieve this layer separation. -For example, using a `Dockerfile` you could express it in this form (assuming the jar is already unpacked at `target/dependency`): +For example, using a `Dockerfile` you could express it in this form: [indent=0] ---- - FROM openjdk:8-jdk-alpine - VOLUME /tmp - ARG DEPENDENCY=target/dependency - COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib - COPY ${DEPENDENCY}/META-INF /app/META-INF - COPY ${DEPENDENCY}/BOOT-INF/classes /app - ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"] + FROM openjdk:8-jdk-alpine AS builder + WORKDIR target/dependency + COPY ./target/*.jar . + RUN jar -xf ./*.jar + + FROM openjdk:8-jre-alpine + EXPOSE 8080 + VOLUME /tmp + ARG DEPENDENCY=target/dependency + COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib + COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF + COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app + ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"] ----