Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1d6492

Browse files
committedNov 7, 2019
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 <guillaume.lours@docker.com>
1 parent fa97766 commit f1d6492

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
 

‎spring-boot-project/spring-boot-docs/src/main/asciidoc/deployment.adoc

+14-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,23 @@ Once you have unpacked the jar file, you can also get an extra boost to startup
3535

3636
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).
3737
There is more than one way to achieve this layer separation.
38-
For example, using a `Dockerfile` you could express it in this form (assuming the jar is already unpacked at `target/dependency`):
38+
For example, using a `Dockerfile` you could express it in this form:
3939

4040
[indent=0]
4141
----
42-
FROM openjdk:8-jdk-alpine
43-
VOLUME /tmp
44-
ARG DEPENDENCY=target/dependency
45-
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
46-
COPY ${DEPENDENCY}/META-INF /app/META-INF
47-
COPY ${DEPENDENCY}/BOOT-INF/classes /app
48-
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"]
42+
FROM openjdk:8-jdk-alpine AS builder
43+
WORKDIR target/dependency
44+
COPY ./target/*.jar .
45+
RUN jar -xf ./*.jar
46+
47+
FROM openjdk:8-jre-alpine
48+
EXPOSE 8080
49+
VOLUME /tmp
50+
ARG DEPENDENCY=target/dependency
51+
COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib
52+
COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF
53+
COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app
54+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"]
4955
----
5056

5157

0 commit comments

Comments
 (0)
Please sign in to comment.