BT

Jib, a Java Container Image Builder from Google

| by Diogo Carleto Follow 39 Followers on Aug 22, 2018. Estimated reading time: 1 minute |

Google recently announced Jib, an open-source container image builder that lets Java developers build Java containers using well-known Java tools such as Maven or Gradle. Developers are not required to write a Dockerfile or have Docker installed in order to build an image.

Jib is implemented in Java and runs as part of a Maven or Gradle build. Jib's build approach separates the Java application into multiple layers, so when there are any code changes, only those changes are rebuilt, rather than the entire application. By default, these layers are layered on top of a distroless base image, which is an image that contains only the developer's application and its runtime dependencies. The following images compare the Docker and Jib build flows:

Docker build flow:

Jib build flow:

To start using Jib, developers just need to add one of the available plugins for Maven or Gradle to the build file and configure the target image. Below are some examples illustrating a build to a container registry and a to a Docker daemon:

Maven

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <version>0.9.0</version>
  <configuration>
    <to>
      <image>myimage</image>
    </to>
  </configuration>
</plugin>
# Builds to a container image registry.
$ mvn compile jib:build
# Builds to a Docker daemon.
$ mvn compile jib:dockerBuild

Gradle

plugins {
  id 'com.google.cloud.tools.jib' version '0.9.8'
}
jib.to.image = 'myimage'
# Builds to a container image registry.
$ gradle jib
# Builds to a Docker daemon.
$ gradle jibDockerBuild

For users who require authenticating with private registries, Jib provides Docker credential helpers. Users can also define credentials in their Maven settings. Some common credential helpers included are Google Container Registry, AWS Elastic Container Registry, and Docker Hub Registry. The following is an example using credential helpers:

<configuration>
  ...
  <from>
    <image>aws_account_id.dkr.ecr.region.amazonaws.com/my-base-image</image>
    <credHelper>ecr-login</credHelper>
  </from>
  <to>
    <image>gcr.io/my-gcp-project/my-app</image>
    <credHelper>gcr</credHelper>
  </to>
  ...
</configuration>

More information can be found on the GitHub repo.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT