Skip to content

Commit 434678d

Browse files
committed
Finished the section with manual dockerfiles
1 parent 2dfa9ac commit 434678d

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

content/post/dockerize-spring-boot.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ image:
2828
projects: []
2929
---
3030

31-
# Why?
31+
## Introduction
3232

3333
In this post, I'd like to present a few options to ship a spring boot application in a docker container. There are many easy ways to *dockerize a spring boot* (probably a nice google hit search), but I don't see too much discussion around the pros and cons. So let's jump into it
3434

@@ -82,7 +82,7 @@ curl http://localhost:8080/ping
8282

8383
Our application is ready, so let's create a docker image for it. First let's
8484

85-
```Dockerfile
85+
```sh
8686
FROM eclipse-temurin:21
8787
LABEL org.opencontainers.image.authors="Norbert Benczur"
8888
RUN mkdir /opt/app
@@ -94,20 +94,46 @@ You can build and run the Docker image:
9494

9595
```sh
9696
docker build -t dockerize-spring-boot .
97-
docker run -it -p 8080:8080 --rm dockerize-spring-boot
97+
docker run -it -p 8080:8080 --rm $ dockerize-spring-boot
9898
```
9999

100100
Verify that we can reach our REST API within the container as expected:
101101

102102
```sh
103-
curl http://localhost:8080/ping
103+
$ curl http://localhost:8080/ping
104104
> Pong!
105105
```
106106

107107
Are we done? - Not at all.
108108

109109
### What's the problem?
110110

111-
Creating `Dockerfile` manually has it pros and cons. It's the most flexible solution where you control everything. No dependency needed.
111+
Creating `Dockerfile` manually has its pros and cons. It's the most flexible solution where you control everything. No dependency needed.
112+
113+
The problem comes when you need more than a `Hello World` example.
114+
115+
#### Repetitive
116+
117+
When you have more than 1 java app to dockerize, the number of dockerfiles starts to grow and you have to maintain and update each file independently.
118+
119+
#### Efficiency
120+
121+
In this simple example, we defined our base image and started our *fat jar*. But is that the most optimal way to build and run a spring boot (or any other java) application?
122+
For example let's change a single file in our application and build the image again:
123+
124+
```sh
125+
# Let's measure the re-build
126+
$ time ( ./gradlew build -x test; docker build -t dockerize-spring-boot .)
127+
> ..
128+
> => [3/3] COPY build/libs/dockerize-spring-boot-*.jar /opt/app/myapp.jar
129+
> ..
130+
> real 0m7,640s
131+
```
132+
133+
So even a single change could cause the jar to be re-built and copied again. We are obviously not using the benefits of docker layers.
134+
135+
Can't we leverage other people's work rather than trying to come up with most optimal `Dockerfile` ourself?
136+
137+
## Use Buildpack
112138

113-
The problem comes when you need more then a *`Hello World` example.
139+
TBD

0 commit comments

Comments
 (0)