Table of Contents
What is Google Jib?
Google Jib is a Plugin developed by Google engineers to build and containerize Java Applications without a docker file.
Jib Plugin is available with Maven and Gradle, or you can also use it as a library.

How to Use Google Jib with Maven or Gradle
To use the Google Jib plugin you need to add it to your project dependency as a plugin.
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<to>
<image>gcr.io/PROJECT/IMAGE</image>
</to>
</configuration>
</plugin>
In the above dependency, we are using the Google repository as a container registry. If you are using any other public or private container registry you need to replace the details.
Replace :
Project with you Project Details
Image with you Image Name
Build and Publish Docker Images Using Jib
mvn compile jib:build
The above command will run a pre-defined jib task to build and publish images to the repository.
Customize Your Jib Image Configuration
Similar to Dockerfile you can add environment variables to the Jib build & update the base image used.
How to Add Environment Variables in Jib
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.8.0</version>
<configuration>
<to>
<image>gcr.io/PROJECT/IMAGE</image>
</to>
<container>
<environment>
<ENV_VAR>VALUE</ENV_VAR>
</environment>
</container>
</configuration>
</plugin>
In the above configuration replace the details.
Replace:
Project with you Project Details
Image with you Image Name
ENV_VAR with the Name of the variable
Value with the desired value
How to Change the Base Image in Jib
For creating a container image base image is used as the base layer and then other layers are added to generate the final image.
As per our requirements, we can update the base image as needed. For example, if a Java base image is needed we can update to “alpine:3” or “openjdlk: VERSION“
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.8.0</version>
<configuration>
<from>
<image>gcr.io/PROJECT/BASE_IMAGE</image>
</from>
<to>
<image>gcr.io/PROJECT/IMAGE_NAME</image>
</to>
</configuration>
</plugin>
Conclusion: Why Use Jib for Java Containers?
Google Jib Separates overhead of docker management while pushing changes to new/existing images. Also its integration with build tools like Maven and Gradle helps to ease the process of creating container images without Dockerfile.
Leave a Reply