- Build Container Images with Jib
This guide describes how to build container images for Helidon applications using Jib and Maven.
What You Need
| About 10 minutes |
| Helidon Prerequisites |
Creating a Docker Image Using Jib
Jib is a java tool chain for building Docker images for Java applications. It is integrated with Maven and Gradle and uses a distroless base image to produce small images.
Jib does not require the docker command or the Docker daemon, there is no need to solve the Docker-in-Docker problem in order to build Docker images as part of your continuous integration.
The docker command is only required for local usage when registering images in your local Docker registry.
The example below shows how to build an image and register it in the local registry using the jib-maven-plugin.
Add the following plugin declaration to your pom.xml:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.10.1</version>
<configuration>
<to>
<image>jib-${project.artifactId}</image>
<tags>
<tag>${project.version}</tag>
<tag>latest</tag>
</tags>
</to>
<container>
<!-- good defaults intended for containers -->
<jvmFlags>
<jmxFlag>-server</jmxFlag>
<jmxFlag>-Djava.awt.headless=true</jmxFlag>
<jmxFlag>-XX:+UnlockExperimentalVMOptions</jmxFlag>
<jmxFlag>-XX:+UseCGroupMemoryLimitForHeap</jmxFlag>
<jmxFlag>-XX:InitialRAMFraction=2</jmxFlag>
<jmxFlag>-XX:MinRAMFraction=2</jmxFlag>
<jmxFlag>-XX:MaxRAMFraction=2</jmxFlag>
<jmxFlag>-XX:+UseG1GC</jmxFlag>
</jvmFlags>
<mainClass>${mainClass}</mainClass>
<ports>
<port>8080</port>
</ports>
</container>
</configuration>
<executions>
<execution>
<goals>
<goal>dockerBuild</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>By default, Jib uses distroless/java as the base image. You can override the default with configuration see the documentation
mvn packagedocker run --rm -p 8080:8080 jib-helidon-quickstart-securl -X GET http://localhost:8080/greetdocker images jib-quickstart-se:latestREPOSITORY TAG IMAGE ID CREATED SIZE
jib-quickstart-se latest 384aebda5594 48 years ago 124MB - Ignore the fact that it says the image was created 48 years ago. Refer to the Jib FAQ for explanations.
the Jib image is smaller because of the use of a distroless base image.