From 6cf05aeb5038433abe198e713d0eb23a91e704cf Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Thu, 7 Nov 2019 17:39:29 +0100 Subject: [PATCH 1/2] Improve Deploying to Containers section See gh-18932 --- .../src/main/asciidoc/deployment.adoc | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 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..bb7d9a68f25b 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,19 +35,29 @@ 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 + ARG fatjar + COPY ${fatjar} app.jar + RUN jar -xf ./app.jar + + FROM openjdk:8-jre-alpine + 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"] +---- +and then build your docker image by passing the full path to your application jar: +[indent=0] +---- +docker build --build-arg fatjar=./full/path/to/your/springboot/app.jar ---- - [[cloud-deployment]] From d08b43673553edeedbe276b8b674a87ea81b38b0 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 13 Nov 2019 13:34:01 +0100 Subject: [PATCH 2/2] Polish "Improve Deploying to Containers section" See gh-18932 --- .../src/main/asciidoc/deployment.adoc | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 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 bb7d9a68f25b..43528623db69 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 @@ -39,27 +39,30 @@ For example, using a `Dockerfile` you could express it in this form: [indent=0] ---- - FROM openjdk:8-jdk-alpine AS builder - WORKDIR target/dependency - ARG fatjar - COPY ${fatjar} app.jar - RUN jar -xf ./app.jar - - FROM openjdk:8-jre-alpine - 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"] ----- -and then build your docker image by passing the full path to your application jar: + FROM openjdk:8-jdk-alpine AS builder + WORKDIR target/dependency + ARG appjar + COPY ${appjar} app.jar + RUN jar -xf ./app.jar + + FROM openjdk:8-jre-alpine + 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"] +---- + +Assuming the above `Dockerfile` is the current directory, your docker image can be built specifying the path to your application jar, as show in the following example: + [indent=0] ---- -docker build --build-arg fatjar=./full/path/to/your/springboot/app.jar + docker build --build-arg appjar=path/to/myapp.jar . ---- + [[cloud-deployment]] == Deploying to the Cloud Spring Boot's executable jars are ready-made for most popular cloud PaaS (Platform-as-a-Service) providers.