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

问题描述 投票:2回答:1

使用以下插件

<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

docker maven-plugin fabric8 docker-maven-plugin
1个回答
0
投票

在研究了maven-docker-plugin的Build Configuration之后,还有一个buildOptions属性也可以使用。

buildOptions还指出

这些选项映射到Docker远程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>
© www.soinside.com 2019 - 2024. All rights reserved.