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

Fabric8 docker-maven-plugin unable set labels to an image

使用以下插件

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