////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
////
= Quarkus - Container Images

include::./attributes.adoc[]

Quarkus provides extensions for building (and pushing) container images. Currently it supports:

- <<#jib,Jib>>
- <<#docker,Docker>>
- <<#s2i,S2I>>

== Container Image extensions

[#jib]
=== Jib

The extension `quarkus-container-image-jib` is powered by https://github.com/GoogleContainerTools/jib[Jib] for performing container image builds.
The major benefit of using Jib with Quarkus is that all the dependencies (everything found under `target/lib`) are cached in a different layer than the actual application making rebuilds really fast and small (when it comes to pushing).
Another important benefit of using this extension is that it provides the ability to create a container image without having to have any dedicated client side tooling (like Docker) or running daemon processes (like the Docker daemon)
when all that is needed is the ability to push to a container image registry.

To use this feature, add the following extension to your project:

[source,shell]
----
./mvnw quarkus:add-extension -Dextensions="container-image-jib"
----

NOTE: In situations where all that is needed to build a container image and no push to a registry is necessary (essentially by having set `quarkus.container-image.build=true` and left `quarkus.container-image.push` unset - it defaults to `false`), then this extension creates a container image and registers
it with the Docker daemon. This means that although Docker isn't used to build the image, it is nevertheless necessary. Also note that using this mode, the built container image *will*
show up when executing `docker images`.

[#docker]
=== Docker

The extension `quarkus-container-image-docker` is using the Docker binary and the generated Dockerfiles under `src/main/docker` in order to perform Docker builds.

To use this feature, add the following extension to your project.

[source,shell]
----
./mvnw quarkus:add-extension -Dextensions="container-image-docker"
----

[#s2i]
=== S2I

The extension `quarkus-container-image-s2i` is using S2I binary builds in order to perform container builds inside the OpenShift cluster.
The idea behind the binary build is that you just upload the artifact and its dependencies to the cluster and during the build they will be merged to a builder image (defaults to `fabric8/s2i-java`).

The benefit of this approach, is that it can be combined with OpenShift's `DeploymentConfig` that makes it easy to roll out changes to the cluster.

To use this feature, add the following extension to your project.

[source,xml]
----
./mvnw quarkus:add-extension -Dextensions="container-image-s2i"
----

S2I builds require creating a `BuildConfig` and two `ImageStream` resources, one for the builder image and one for the output image.
The creation of such objects is being taken care of by the Quarkus Kubernetes extension.

== Building

To build a container image for your project, `quarkus.container-image.build=true` needs to be set using any of the ways that Quarkus supports.

[source, subs=attributes+]
----
./mvnw clean package -Dquarkus.container-image.build=true
----

== Pushing

To push a container image for your project, `quarkus.container-image.push=true` needs to be set using any of the ways that Quarkus supports.

[source, subs=attributes+]
----
./mvnw clean package -Dquarkus.container-image.push=true
----

NOTE: If no registry is set (using `quarkus.container-image.registry`) then `docker.io` will be used as the default.

== Customizing

The following properties can be used to customize the container image build process.

=== Container Image Options

include::{generated-dir}/config/quarkus-container-image.adoc[opts=optional, leveloffset=+1]

=== Jib Options

In addition to the generic container image options, the `container-image-jib` also provides the following options:

include::{generated-dir}/config/quarkus-container-image-jib.adoc[opts=optional, leveloffset=+1]

=== Docker Options

In addition to the generic container image options, the `container-image-docker` also provides the following options:

include::{generated-dir}/config/quarkus-container-image-docker.adoc[opts=optional, leveloffset=+1]

=== S2I  Options

In addition to the generic container image options, the `container-image-s2i` also provides the following options:

include::{generated-dir}/config/quarkus-container-image-s2i.adoc[opts=optional, leveloffset=+1]
