Skip to content

Commit f7a5513

Browse files
committed
Added the section about jib.
1 parent 78978b4 commit f7a5513

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

content/post/dockerize-spring-boot.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Many of the problems that I mentioned previously comes from that the fact that w
144144

145145
We can use paketo by executing the following gradle (or maven) task:
146146

147-
```gradle
147+
```sh
148148
./gradlew bootBuildImage
149149
```
150150

@@ -212,8 +212,8 @@ BUILD SUCCESSFUL in 1m 57s
212212
Let's run and test our the newly created images as before:
213213

214214
```sh
215-
$ docker run -it -p 8080:8080 --rm dockerize-spring-boot:0.0.1-SNAPSHOT
216-
$ curl http://localhost:8080/ping
215+
$ docker run -it -p 8081:8080 --rm dockerize-spring-boot:0.0.1-SNAPSHOT
216+
$ curl http://localhost:8081/ping
217217
> Pong!
218218
```
219219

@@ -226,4 +226,38 @@ For more information please have a look on the Spring doc [Packaging OCI Images]
226226
227227
### Jib
228228
229-
*Coming soon...*
229+
Another option that I would like to present is called [Jib](https://github.com/GoogleContainerTools/jib). This is part of Google's container tools to dockerize Java applications, similar what we have seen in the previous chapter.
230+
231+
Let's use it via the [gradle plugin](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin). You can add the plugin to the `build.gradle` file:
232+
233+
```gradle
234+
plugins {
235+
id 'com.google.cloud.tools.jib' version '3.4.4'
236+
}
237+
```
238+
239+
And then create a docker image:
240+
241+
```sh
242+
./gradlew jibDockerBuild --image=dockerize-spring-boot-jib
243+
```
244+
245+
Let's run and test one last time:
246+
247+
```sh
248+
$ docker run -it -p 8082:8080 --rm dockerize-spring-boot-jib:latest
249+
$ curl http://localhost:8082/ping
250+
> Pong!
251+
```
252+
253+
It's a very rich plugin, so I recommend to spend time how to configure it (for example how to change the base image).
254+
255+
### What's the catch?
256+
257+
The major drawback with these options is that it introduces a dependency to you project (or even a plugin). You have to learn, understand, configure and maintain it. Contributors to (open source) projects can come and go, and there is no guarantee that these project will stay and get updates forever.
258+
259+
This problem is not unique to these plugins, but general for all dependencies, libraries and frameworks that your projects relies on, so make sure that you evaluate before adding it to your project.
260+
261+
## Summary
262+
263+
I hope following this post you gained the knowledge how to dockerize a spring boot application and made it clear that there are always tradeoffs to consider when deciding how to create a docker image based on your application.

0 commit comments

Comments
 (0)