Containerizing Spring Boot Application with Jib | by Ashish Choudhary | Javarevisited | Medium

Смотреть что такое jib в других словарях:

jib: translationSynonyms and related words:avert, avoid, back down, balance, balk, balloon sail, batten, bear off, blench, blink, boggle, cringe, debat… смотреть

A Simple Greeting App

Let’s take a simple spring-boot application and dockerize it using Jib. It’ll expose a simple GET endpoint:

Preparing the Deployment

We’ll also need to set ourselves up locally to authenticate with the Docker repository we want to deploy to.

For this example, we’ll provide our DockerHub credentials to .m2/settings.xml:

Customizing Java Aspects

And, by association, Jib supports numerous Java runtime configurations, too:

  • jvmFlags is for indicating what startup flags to pass to the JVM.
  • mainClass is for indicating the main class, which Jib will attempt to infer automatically by default. 
  • args is where we’d specify the program arguments passed to the main method.

Of course, make sure to check out Jib’s documentation to see all the configuration properties available.

Building an image

To build an image we can do it in the following ways.

  1. IDE

For example, in IntelliJ, you can just go to maven view of your project then go under Plugins>jib then right click and run the maven build. You may want to create an IntelliJ run configuration for this which can run maven goals like clean, compile, etc. then push your image.

2. Using the command line

Just run the below command to build an image of your application. Make sure you have maven installed.

mvn compile jib:build

It will compile, build, and then push the image of your application to the configured container registry.

Читайте также:  Как подписать документ с помощью ЭЦП

Following is the output.

Further reading

You can also read some of my previous articles.

How to jib?

With Jib you can containerize your Java applications in no time just by adding Maven or Gradle plugin to your pom.xml.or build.gradle file. It is that simple. We will be covering Maven first and in later post Gradle. Let’s get started then.

We will be using spring initializr to generate a working spring-boot project. Source code of our SpringBoot application is available here and it just prints a Hello message when the image pushed via Jib and the image is run through docker.

Once we have the setup ready with IDE we can proceed with the next step.

Run the image

We have successfully pushed the image(image name:spring-boot-jib-image) to a docker registry. Now we can run the image using docker.

As you can see that our application is running inside a container. Now just run the curl command and you can see that we got a hello message from our spring-boot application.

Setting credentials for registry

In order to push an image, we would need to add registry credentials to maven settings.xml. Since we are just doing a demo it’s ok to provide credentials this way but avoid using this approach as it is not secure at all. You may want to secure credentials as mentioned here.

Support me

If you like what you just read then you can buy me a coffee.

What is jib?

Jib is Java containerizer from Google that lets Java developers build containers using the build tools like Maven, Gradle etc.

Читайте также:  ЭЦП для ЕГАИС — порядок получения

But that’s not all what is really interesting about Jib is the fact that you don’t need to know anything about installing docker, maintaining Dockerfile, etc. As a developer, you only care about the artifact(jar, war, etc.) you are going to produce and you don’t have to deal with any of the docker nonsense(build/push, etc.).

Wow, this is really powerful!!! But how?


In this article, we have learned how we can containerize our Java applications without docker. Additionally, with Jib you can build images using docker also but that’ not the X factor. Other benefits of using Jib for your Java applications include super easy to integrate, faster builds, reproducible builds, Backed by Google, etc. You can go through this link to know about Jib’s benefits in detail.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *