5

使用以下插件

<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

4

1 回答 1

2

在查看maven-docker-plugin 的Build Configuration之后,还有一个buildOptions可以使用的属性。

buildOptions指出

这些选项映射到 Docker Remote API 中作为查询参数列出的选项

Docker Remote API中的查询参数有labels一个参数。

标签:要在图像上设置的任意键/值标签,作为字符串对的 JSON 映射。

所以我们必须在构建选项中指定一个 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>
于 2020-03-11T06:09:31.340 回答