Traditionally, containerizing a Java application requires writing a Dockerfile
, building an image with Docker, and then pushing it to a registry. While effective, this approach introduces extra steps and dependencies.
Google Jib eliminates that complexity. It integrates directly into your build tool (Maven or Gradle), allowing you to build and push container images straight from your Java project β no Dockerfile
, no docker build
, and not even Docker itself on your machine.
π οΈ Why Use Jib?
- No Docker daemon required (works even if Docker isnβt installed).
- Build directly from Maven/Gradle (seamless developer experience).
- Layered image caching for faster incremental builds.
- Optimized images with minimal overhead.
π Step 1: Add Jib to Your Build Tool
For Maven:
Add the plugin to your pom.xml
:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.2</version>
</plugin>
For Gradle:
Add the plugin in build.gradle
:
plugins {
id 'com.google.cloud.tools.jib' version '3.4.2'
}
π Step 2: Configure Image Destination
Tell Jib where to push your image.
Example for a private registry (say GCP Artifact Registry or Harbor):
Maven
<configuration>
<to>
<image>myregistry.example.com:5000/myteam/myapp:1.0</image>
</to>
</configuration>
Gradle
jib {
to {
image = 'myregistry.example.com:5000/myteam/myapp:1.0'
}
}
π Step 3: Build and Push the Image
- With Maven:
mvn compile jib:build
- With Gradle:
./gradlew jib
π This command builds your app, creates a Docker/OCI image, and pushes it directly to the registry.
π Step 4: Build Image Locally (Optional)
If you want the image only on your local machine (not pushed to a registry):
- Maven:
mvn compile jib:dockerBuild
- Gradle:
./gradlew jibDockerBuild
π Step 5: Verify the Image
Pull from your private registry (if you pushed):
docker pull myregistry.example.com:5000/myteam/myapp:1.0
Or run locally if built with jibDockerBuild
:
docker run -p 8080:8080 myregistry.example.com:5000/myteam/myapp:1.0
β‘ Pro Tips
-
Environment-specific configs: You can set image name, tags, and credentials via
application.properties
or CI/CD pipelines. -
No JAR needed: Jib packages classes/resources directly, skipping the need for
mvn package
before building. - Faster CI/CD: Great for Kubernetes deployments with GitOps workflows.
- Secure builds: Works without requiring root access to Docker.
β Conclusion
With Google Jib, you can skip writing Dockerfile
s and bypass Docker altogether. It integrates smoothly with Maven/Gradle, builds optimized images, and pushes them directly to your private or public registry.
This approach is especially valuable in enterprises where:
- Docker isnβt installed on build servers.
- Teams want faster, repeatable, and secure builds.
- CI/CD pipelines need minimal dependencies.
Top comments (0)