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

标签 docker maven-plugin fabric8 docker-maven-plugin

使用以下插件

<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/

相关文章:

maven-2 - Maven : How can my mojo access its own resources?

maven - Kubernetes pod - 图像从未拉出错误

java - Tekton 中有未知字段 "container"

amazon-web-services - 有没有办法在 Docker 群中运行每个服务以使用不同的 IAM 角色运行

maven-2 - maven-dependency-plugin:copy 尝试复制类

docker - 如何删除 Travis CI 上的缓存?

java - mvn混淆器: Is there possible obfuscate dependency before copying

java - 将配置文件添加到子容器不会在集合中的其他子容器中复制?

docker - FreeRadius教程中预期的Access-Accept获得Access-Reject

docker - Ingress-nginx日志-出现很多奇怪的条目