Objective
Introduce what jib is, how to use jib to build docker image of Spring Boot app
Requirement & Prerequisites
Machine
- Java 8+
- Docker runtime
- Docker hub account or other registry sapce
Human
- Basic Spring Boot understanding
- Basic Docker immae, container knowledge
Introduction
Jib is
- a tool to help you containerize your java app without having docker deamon and Dockerfile
- an open source project by Google, jib github repo
- a plugin supported for both gradle and maven
What is the difference from common Dockerfile build flow?
a blog post from GCP Blog describes very clearly (image from: Introducing Jib — build Java Docker images better)
— highly recommend to read this blog post if you want learn jib more —
Demo with Spring Boot Greeting App
clone this repo beforehand: Spring Boot Guides - Building a RESTful Web Service
add jib plugins build.gradle
1 | plugins { |
Build image without dokcer deamon (authentication of image registry is necessary)
Default is docker hub registry.
But Azure Container Registry (ACR) , Google Container Registry (GCR) and Amazon Elastic Container Registry (ECR) are all supported
1 | # login |
Build image with dokcer deamon, and run the container
1 | # build image |
make a request by curl command
1 | $ curl -s http://localhost:8080/greeting |
Yeah!!! Building a java app image is so easy!!!
Summary
Through this article, we can see how easy it is to build an java app image without Dockerfile or Docker deamon.
The reason I like jib is, I don’t have to install docker on the build server, like Jenkins, and I still can build an image and push to the target image registry.
In our team, we have already lots of build jar file projects on Jenkins server, and I don’t want to ruin it or take more time to install it. That’s why I seek for the solution and use jib instead.