guides.jib.adoc Maven / Gradle / Ivy
///////////////////////////////////////////////////////////////////////////////
Copyright (c) 2018, 2024 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
///////////////////////////////////////////////////////////////////////////////
= Build Container Images with Jib
:description: Helidon Jib Guide
:keywords: helidon, guide, docker, jib
:rootdir: {docdir}/..
include::{rootdir}/includes/attributes.adoc[]
This guide describes how to build container images for Helidon applications
using Jib and Maven.
== What You Need
|===
|About 10 minutes
| xref:../about/prerequisites.adoc[Helidon Prerequisites]
|===
== Creating a Docker Image Using Jib
link:https://github.com/GoogleContainerTools/jib[Jib] is a java tool chain for building Docker images for Java
applications. It is integrated with Maven and Gradle and uses a
link:https://github.com/GoogleContainerTools/distroless[distro-less] 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.
NOTE: 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:
[source,xml]
----
com.google.cloud.tools
jib-maven-plugin
0.10.1
jib-${project.artifactId}
${project.version}
latest
-server
-Djava.awt.headless=true
-XX:+UnlockExperimentalVMOptions
-XX:+UseCGroupMemoryLimitForHeap
-XX:InitialRAMFraction=2
-XX:MinRAMFraction=2
-XX:MaxRAMFraction=2
-XX:+UseG1GC
${mainClass}
8080
dockerBuild
package
----
NOTE: By default, Jib uses link:https://github.com/GoogleContainerTools/distroless/tree/master/java[distroless/java] as
the base image. You can override the default with configuration see the
link:{jib-base-url}/README.md#extended-usage[documentation]
[source,bash]
.Package the updated application
----
mvn package
----
[source,bash]
.Run the image
----
docker run --rm -p 8080:8080 jib-helidon-quickstart-se
----
[source,bash]
.Ping the application
----
curl -X GET http://localhost:8080/greet
----
[source,bash]
.Take a look at the image size
----
docker images jib-quickstart-se:latest
----
[source,bash]
----
REPOSITORY TAG IMAGE ID CREATED SIZE
jib-quickstart-se latest 384aebda5594 48 years ago 124MB <1>
----
<1> Ignore the fact that it says the image was created 48 years ago. Refer to
the link:{jib-base-url}/../docs/faq.md#why-is-my-image-created-48-years-ago[Jib FAQ] for explanations.
NOTE: the Jib image is smaller because of the use of a distroless base image.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy