Skip to content

Building a Container with Jib

homepage-banner

Introduction

Docker requires permissions to install a service running as a daemon, which is a privileged process in your operating system. Nowadays, there are also dockerless solutions available for developers, such as Jib.

Jib is an open-source framework for Java made by Google, which can build OCI-compliant container images without the need for Docker or any container runtime. Jib comes as a library that Java developers can import into their Maven or Gradle projects. This means you can create a container image for your app without writing or maintaining any Dockerfiles, delegating this complexity to Jib.

Using Jib

The easiest way to start building a container image with Jib on an existing Maven project is to add the plug-in via the command line:

mvn compile com.google.cloud.tools:jib-maven-plugin:3.2.0:build -Dimage=<MY IMAGE>

Alternatively, you can add Jib as a plug-in to your pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.6.3</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.redhat</groupId>
 <artifactId>hello</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>hello</name>
 <description>Demo project for Spring Boot</description>
 <properties>
  <java.version>11</java.version>
 </properties>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>

 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>

</project>

To create a container image without using Docker and push it directly to a container registry, run the following command. In this example, we will use Quay.io and store the container image at quay.io/gitops-cookbook/jib-example:latest. You will need to provide your registry credentials:

mvn compile com.google.cloud.tools:jib-maven-plugin:3.2.0:build \
-Dimage=quay.io/gitops-cookbook/jib-example:latest \
-Djib.to.auth.username=<USERNAME> \
-Djib.to.auth.password=<PASSWORD>

Conclusion

Containerization has become an essential part of modern software development, and Jib has made the process of building and deploying container images simpler and more efficient. With the introduction of the Dockerless Jib plugin, developers can now build and deploy container images without the need for Docker, saving time and resources. The future of containerization is undoubtedly exciting, and Dockerless Jib is leading the way.

Reference

  • GitOps Cookbook by Natale Vinto and Alex Soto Bueno
  • https://github.com/GoogleContainerTools/jib
  • https://github.com/gitops-cookbook/chapters/blob/main/chapters/ch03/springboot-app/pom.xml
Leave a message