Skip to content

Commit 7d54054

Browse files
committed
Merge pull request spring-projects#18932 from glours
* pr/18932: Polish "Improve Deploying to Containers section" Improve Deploying to Containers section Closes spring-projectsgh-18932
2 parents a74d5b1 + d08b436 commit 7d54054

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,32 @@ 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
42+
FROM openjdk:8-jdk-alpine AS builder
43+
WORKDIR target/dependency
44+
ARG appjar
45+
COPY ${appjar} app.jar
46+
RUN jar -xf ./app.jar
47+
48+
FROM openjdk:8-jre-alpine
4349
VOLUME /tmp
4450
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
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
4854
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"]
4955
----
5056

57+
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:
58+
59+
[indent=0]
60+
----
61+
docker build --build-arg appjar=path/to/myapp.jar .
62+
----
63+
5164

5265

5366
[[cloud-deployment]]

0 commit comments

Comments
 (0)