Container Image
容器镜像 extensions
Jib
quarkus-container-image-jib
extension 是由 Jib 提供的,用于构建容器镜像。
使用 Quarkus 的 Jib的主要好处是,所有依赖项 (在 target/lib
下找到的一切) 都被缓存到不同于实际应用程序的层中,使重建真正快而小(当它被推送时)。
使用此 extension 的另外一个好处是它无需额外的客户端工具(像 Docker) 或守护进程(像 Docker daemon)就能创建容器镜像并推送到容器镜像注册中心。
要使用此功能,请在您的项目中添加以下扩展:
./mvnw quarkus:add-extension -Dextensions="container-image-jib"
有时只构建容器镜像不推送到注册中心(主要是设置 quarkus.container-image.build=true 然后留着 quarkus.container-image.push 不设置 - 它默认是 false ),此 extension 会创建容器镜像并使用 Docker daemon 注册。 这意味着虽然构建镜像时没有使用 Docker ,但它是必要的。 还请注意,使用此模式构建的容器镜像 将
在执行 docker images 时看到。
|
Docker
quarkus-container-image-docker
extension 使用 Docker 程序和 src/main/docker
下生成的 Dockerfiles 来执行 Docker 构建。
要使用此功能,请向您的项目添加以下 extension。
./mvnw quarkus:add-extension -Dextensions="container-image-docker"
S2I
quarkus-container-image-s2i
extension 使用 S2I binary 以便在 OpenShift 集群内执行容器构建。
二进制构建背后的想法是,你只是将制品及其依赖上传到集群,在构建过程中,它们将被合并到预构建镜像(默认为 fabric8/s2i-java
)。
这种方式的好处是,它可以与 OpenShift 的 DeploymentConfig
结合起来,它使得对集群进行更改变得容易。
要使用此功能,请向您的项目添加以下extension。
./mvnw quarkus:add-extension -Dextensions="container-image-s2i"
S2I 构建需要创建一个 BuildConfig
和两个 ImageStream
资源,一个用于 builder image ,另一个用于输出镜像。
Quarkus Kubernetes extension 负责创建这些。
构建
要为您的项目构建一个容器镜像,需要使用 Quarkus 支持的任何方式设置 quarkus.container-image.build=true
。
./mvnw clean package -Dquarkus.container-image.build=true
推送
要为您的项目构建一个容器镜像,需要使用 Quarkus 支持的任何方式设置 quarkus.container-image.pus=true
。
./mvnw clean package -Dquarkus.container-image.push=true
如果没有设置注册中心(使用 quarkus.container-image.registry ),默认使用 docker.io 。
|
定制
以下属性可以用于定制容器镜像构建过程。
容器镜像选项
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
The group the container image will be part of |
string |
|
The name of the container image. If not set defaults to the application name |
string |
|
The tag of the container image. If not set defaults to the application version |
string |
|
The container registry to use |
string |
|
The username to use to authenticate with the registry |
string |
|
The password to use to authenticate with the registry |
string |
|
Whether or not insecure registries are allowed |
boolean |
|
Whether or not a image build will be performed. |
boolean |
|
Whether or not an image push will be performed. |
boolean |
|
Jib选项
除了通用的容器镜像选项外,container-image-jib
也提供了以下选项:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
The base image to be used when a container image is being produced for the jar build |
string |
|
The base image to be used when a container image is being produced for the native binary build |
string |
|
Additional JVM arguments to pass to the JVM when starting the application |
list of string |
|
Additional arguments to pass when starting the native application |
list of string |
|
Environment variables to add to the container image |
|
required |
Docker 选项
除了通用的容器镜像选项外, container-image-docker
还提供以下选项:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
Path to the the JVM Dockerfile. If not set ${project.root}/src/main/docker/Dockerfile.jvm will be used If set to an absolute path then the absolute path will be used, otherwise the path will be considered relative to the project root |
string |
|
Path to the the JVM Dockerfile. If not set ${project.root}/src/main/docker/Dockerfile.native will be used If set to an absolute path then the absolute path will be used, otherwise the path will be considered relative to the project root |
string |
S2I 选项
除了通用的容器镜像选项外, container-image-s2i
也提供了以下选项:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
The base image to be used when a container image is being produced for the jar build |
string |
|
The base image to be used when a container image is being produced for the native binary build |
string |
|
Additional JVM arguments to pass to the JVM when starting the application |
list of string |
|
Additional arguments to pass when starting the native application |
list of string |
|
The directory where the jar is added during the assemble phase. This is dependant on the s2i image and should be supplied if a non default image is used. |
string |
|
The resulting filename of the jar in the s2i image. This option may be used if the selected s2i image uses a fixed name for the jar. |
string |
|
The directory where the native binary is added during the assemble phase. This is dependant on the s2i image and should be supplied if a non-default image is used. |
string |
|
The resulting filename of the native binary in the s2i image. This option may be used if the selected s2i image uses a fixed name for the native binary. |
string |
|
The build timeout. |
|
About the Duration format
The format for durations uses the standard You can also provide duration values starting with a number.
In this case, if the value consists only of a number, the converter treats the value as seconds.
Otherwise, |