Jib — Build Java Container Images Without Docker
Jib is a Google-built tool that containerizes Java applications directly from Maven or Gradle without a Dockerfile or Docker daemon, producing optimized, layered OCI images.
What it is
Jib is a container image builder created by Google that packages Java applications into optimized, layered OCI images directly from your Maven or Gradle build. No Dockerfile required. No Docker daemon required. Jib understands Java application structure and creates efficient image layers that separate dependencies from application code.
This tool is for Java developers and platform teams who want to containerize applications without learning Docker internals. It integrates into existing build tools so containerization is just another build step.
How it saves time or tokens
Jib eliminates the Dockerfile-write-build-push workflow. You add a plugin to your pom.xml or build.gradle, and mvn jib:build or gradle jib pushes a production-ready image. Layer optimization means only changed layers are rebuilt and pushed, saving CI time. The build is reproducible: same source always produces the same image.
How to use
- Add the Jib plugin to your Maven or Gradle build file.
- Configure the target image registry.
- Run the build command.
- The image is pushed directly to the registry.
<!-- Maven pom.xml -->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<to>
<image>gcr.io/myproject/myapp</image>
</to>
</configuration>
</plugin>
# Build and push image (no Docker needed)
mvn compile jib:build
# Build to local Docker daemon
mvn compile jib:dockerBuild
# Build to a tar file
mvn compile jib:buildTar
Example
Gradle configuration:
plugins {
id 'com.google.cloud.tools.jib' version '3.4.0'
}
jib {
from {
image = 'eclipse-temurin:21-jre'
}
to {
image = 'gcr.io/myproject/myapp'
tags = ['latest', project.version]
}
container {
mainClass = 'com.myapp.Main'
ports = ['8080']
jvmFlags = ['-Xms256m', '-Xmx512m']
}
}
Run gradle jib and the image is built and pushed.
Related on TokRepo
- DevOps tools — Container and deployment tools
- Automation tools — Build automation for CI/CD
Common pitfalls
- Jib pushes directly to a registry by default. Ensure your registry credentials are configured in Maven settings or Gradle properties.
- The base image must be compatible with your JDK version. Mismatched JDK versions cause runtime errors.
- Native dependencies or custom filesystem modifications need extra configuration since there is no Dockerfile to customize.
- Jib optimizes for standard Java applications. If your app has non-Java components (native binaries, config files in unusual locations), you need Jib's extra directories feature.
- Build reproducibility requires pinning the base image tag. Using
latestcreates non-reproducible builds. - Review the official documentation before deploying to production to ensure compatibility with your specific environment and requirements.
Frequently Asked Questions
No. Jib builds container images without a Docker daemon. It constructs image layers directly and pushes them to a registry. You can optionally use jib:dockerBuild to build to a local Docker daemon if you have one.
Jib supports any OCI-compliant registry: Docker Hub, Google Container Registry, AWS ECR, Azure Container Registry, GitHub Container Registry, and private registries. Authentication is configured through Maven settings or Gradle properties.
Jib separates your application into multiple layers: dependencies, resources, and classes. Since dependencies change less frequently than application code, most builds only rebuild and push the classes layer, saving time and bandwidth.
Yes. Set the from.image configuration to any base image. Common choices include eclipse-temurin, amazoncorretto, or custom base images. Jib defaults to a distroless Java base image for minimal attack surface.
Yes. Jib automatically detects Spring Boot applications and configures the main class and classpath correctly. No special configuration is needed for standard Spring Boot projects.
Citations (3)
- Jib GitHub— Jib builds Java container images without Docker
- Jib Maven Plugin Docs— Jib Maven plugin configuration
- OCI Image Spec— OCI image specification for container images
Related on TokRepo
Discussion
Related Assets
Cucumber.js — BDD Testing with Plain Language Scenarios
Cucumber.js is a JavaScript implementation of Cucumber that runs automated tests written in Gherkin plain language.
WireMock — Flexible API Mocking for Java and Beyond
WireMock is an HTTP mock server for stubbing and verifying API calls in integration tests and development.
Google Benchmark — Microbenchmark Library for C++
Google Benchmark is a library for measuring and reporting the performance of C++ code with statistical rigor.