TODO: Add a logo and badges.
Jib is a tool for building container images for your Java applications.
- Fast - Your Java application gets broken down into multiple layers, separating dependencies from classes. Deploy your changes faster - don’t wait for Docker to rebuild your entire Java application.
- Native - Reduce your CLI dependencies. Build your Docker image from within Maven or Gradle and push to any registry of your choice. No more writing Dockerfiles and calling docker build/push.
In your Maven Java project, add the plugin to your pom.xml:
<plugin>
<groupId>com.google.com.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<registry></registry>
<repository></repository>
<credentialHelperName></credentialHelperName>
</configuration>
</plugin>
Configure the plugin by changing registry, repository, and credentialHelperName accordingly.
TODO: Add reference for how to get the credential helper.
For example, to build the image gcr.io/my-gcp-project/my-app, the configuration would be:
<configuration>
<registry>gcr.io</registry>
<repository>my-gcp-project/my-app</repository>
<credentialHelperName>gcr</credentialHelperName>
</configuration>
TODO: Add reference for how to get the credential helper.
For example, to build the image aws_account_id.dkr.ecr.region.amazonaws.com/my-app, the configuration would be:
<configuration>
<registry>aws_account_id.dkr.ecr.region.amazonaws.com</registry>
<repository>my-app</repository>
<credentialHelperName>ecr-login</credentialHelperName>
</configuration>
Build your container image with:
$ mvn compile jib:build
Subsequent builds would usually be much faster than the initial build.
Extended configuration options provide additional options for customizing the image build.
| Field | Default | Description |
|---|---|---|
| from | gcr.io/distroless/java |
The base image to build your application on top of. |
| baseImageRegistry | gcr.io |
The registry for the base image |
| baseImageRepository | distroless/java |
The image name/repository of the base image |
| baseImageTag | latest |
The tag for the base image |
| registry | Required | The registry server to push the built image to. |
| repository | Required | The image name/repository of the built image. |
| tag | latest |
The image tag of the built image (the part after the colon). |
| jvmFlags | None | Additional flags to pass into the JVM when running your application. |
| credentialHelperName | Required | The credential helper suffix (following docker-credential-) |
Whereas traditionally a Java application is built as a single image layer with the application JAR, the build strategy here breaks the Java application into multiple layers for more granular incremental builds. When you change your code, only your changes are rebuilt, not your entire application. These layers, by default, are layered on top of a distroless base image.
See also rules_docker for a similar existing container image build tool for the Bazel build system.
TODO: Add more answers.