Containerize Your Java Application Easily With Google’s JIB

Containerize Your Java Application Easily With Google’s JIB

As we all know that docker containers made developer’s life easier by providing solution for “Write once,run anywhere” concept . For making this concept working ,developers are require to create Dokerfile , run Docker daemon , wait for your docker image to build & if all goes well then finally push this image on remote registry . Now doing this all things is not easier for all developer as they are not expert in creating docker images and deploy on private registry . Here comes Google’s new library called JIB , to rescue Java Application Developers.

To use this plugin developer just need to add it as Maven or Gradle dependency & your Java application containerized . Easy right ?

As per google , here is the difference in build flow without Jib and when we use Jib , difference is clear.

While using normal docker build flow it goes this way :

Below is the build flow with Jib :

Below are the Goals this library achieves :

Fast – Its fast because you can now separate your build in multiple layers & deploy only those layer which are changed and not the whole application , which usually takes lots of time in conventional way

Reproducible – It identifies that if content is same then no need to generate the new image again as its always same if content not changed .

Daemonless – Usually we have multiple files to manage the docker build like DockerFile, build script , deploy script etc . But now all this included in your maven/gradle jar .

To add Jib to your maven project :

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <version>0.9.0</version>
  <configuration>
    <to>
      <image>gcr.io/my-project/image-built-with-jib</image>
    </to>
  </configuration>
</plugin>

To build container image registry run following command :

1
mvn compile jib:build

And finally build to docker daemon with following command :

1
mvn compile jib:dockerBuild

 

To add Jib to your gradle project :

plugins {
  id 'com.google.cloud.tools.jib' version '0.9.0'
}

To build container image registry run following command :

1
gradle jib

 

And finally build to docker daemon with following command :And finally build to docker daemon with following command :

1
gradle jibDockerBuild

 

Related Posts