Skip to content

Commit 6cf05ae

Browse files
glourssnicoll
authored andcommitted
Improve Deploying to Containers section
See spring-projectsgh-18932
1 parent a74d5b1 commit 6cf05ae

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,29 @@ 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+
ARG fatjar
45+
COPY ${fatjar} app.jar
46+
RUN jar -xf ./app.jar
47+
48+
FROM openjdk:8-jre-alpine
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"]
55+
----
56+
and then build your docker image by passing the full path to your application jar:
57+
[indent=0]
58+
----
59+
docker build --build-arg fatjar=./full/path/to/your/springboot/app.jar
4960
----
50-
5161

5262

5363
[[cloud-deployment]]

0 commit comments

Comments
 (0)