gpt4 book ai didi

docker - Fabric8 docker-maven-plugin 无法为图像设置标签

转载 作者:行者123 更新时间:2023-12-02 09:41:27 25 4
gpt4 key购买 nike

使用以下插件

<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.33</version

并使用以下配置(仅在此处发布相关位)

    <configuration>
<verbose>build</verbose>
<images>
<image>
<name>${container.imageNameWithTag}</name>
<build>
<labels>
<dummy.label>dummyLabelValue</dummy.label>
</labels>
<contextDir>${project.basedir}/src/main/docker</contextDir>
<assembly>some required assembly </assembly>
</build>
</image>
</images>
</configuration>

<executions>
<execution>
<id>docker-build</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>

但最终图像只有这些标签

        "Labels": {
"org.label-schema.build-date": "20181204",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}

我认为来自 centos 基础镜像,但没有 dummy.label

我是否缺少任何配置,或者配置错误?

该插件的文档位于 Maven Docker Plugin

最佳答案

调查后Build Configuration maven-docker-plugin 中,还有一个 buildOptions 属性也可以使用。

buildOptions 还指出

These options map to the ones listed as query parameters in the Docker Remote API

Docker Remote API中的查询参数有 labels 作为参数。

labels: Arbitrary key/value labels to set on the image, as a JSON map of string pairs.

所以我们必须在构建选项中指定一个 JSON 字符串,如下所示

<configuration>
<verbose>build</verbose>
<images>
<image>
<name>${container.nameWithTag}</name>
<build>
<contextDir>${project.basedir}/src/main/docker</contextDir>
<buildOptions>

<labels>{
"org.label-schema.name":"${container.name}",
"org.label-schema.description":"My Image",
"org.label-schema.vcs-url":"${project.scm.url}",
"org.label-schema.vendor":"Test Vendor",
"org.label-schema.version":"${container.tag}"
}</labels>

</buildOptions>
</build>
</image>
</images>
</configuration>

关于docker - Fabric8 docker-maven-plugin 无法为图像设置标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60504536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com