【问题标题】:Tagging created image with dockerfile-maven-plugin使用 dockerfile-maven-plugin 标记创建的图像
【发布时间】:2017-11-05 10:06:38
【问题描述】:

我正在使用具有以下配置的 dockerfile-maven-plugin:

  <plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.3.6</version>
    <executions>
        <execution>
            <id>build-image</id>
            <goals>
                <goal>build</goal>
            </goals>
            <configuration>
                <tag>latest</tag>
                <repository>root/${project.artifactId}</repository>
                <buildArgs>
                    <APP_NAME>${project.artifactId}</APP_NAME>
                </buildArgs>
            </configuration>
        </execution>
        <execution>
            <id>push-image</id>
            <goals>
                <goal>push</goal>
            </goals>
            <configuration>
                <repository>${docker.registry.url}/root/${project.artifactId}</repository>
            </configuration>
        </execution>
    </executions>
</plugin>

项目部署失败,原因是:

[INFO] The push refers to a repository [my-repository:9090/root/image-name]
[ERROR] An image does not exist locally with the tag: my-repository:9090/root/image-name
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not push image
.
.
.

在构建目标下为存储库添加前缀(与推送目标类似)解决了这个问题。但随后本地创建的图像以存储库标签为前缀。

没有找到任何关于如何在推送任务之前执行标记的文档参考。

换句话说,我希望我的本地 docker 图像在插件执行后包含 2 个图像:

REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
root/image-name                                   latest              7ac1144c607e        21 minutes ago      175MB
my-repository:9090/root/image-name                latest              7ac1144c607e        21 minutes ago      175MB

我的docker版本是:17.06.0-ce

【问题讨论】:

    标签: maven docker plugins docker-maven-plugin


    【解决方案1】:

    即使使用现有的 docker 层,我们也不想重新构建。在第一次执行中,我们构建和推送,在第二次执行中,我们只是标记和推送。

    <build>
      <plugins>
        <plugin>
          <groupId>com.spotify</groupId>
          <artifactId>dockerfile-maven-plugin</artifactId>
          <version>${dockerfile-maven-plugin.version}</version>
          <executions>
            <execution>
              <id>default</id>
              <goals>
                <goal>build</goal>
                <goal>push</goal>
              </goals>
              <configuration>
                <tag>${build.number}</tag>
              </configuration>
            </execution>
            <execution>
              <id>default-2</id>
              <goals>
                <goal>tag</goal>
                <goal>push</goal>
              </goals>
              <configuration>
                <tag>latest</tag>
              </configuration>
            </execution>
          </executions>
          <configuration>
            <repository>${docker-remote.registry}/path/${project.version.lowercase}</repository>
            <buildArgs>
            <EAR_FILE>${project.build.finalName}.ear</EAR_FILE>
            </buildArgs>
            <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
          </configuration>
        </plugin>
      </plugins>
    </build>
    

    【讨论】:

      【解决方案2】:

      在我的配置中添加额外的执行步骤解决了这个问题:

      <execution>
          <id>tag-image</id>
          <phase>deploy</phase>
          <goals>
              <goal>tag</goal>
          </goals>
          <configuration>
              <repository>${docker.registry.url}/root/${project.artifactId}</repository>
          </configuration>
      </execution>
      

      【讨论】:

        【解决方案3】:

        您也可以在成功构建后手动标记您的图像

        mvn dockerfile:tag -Dproject.plugin.dockerfile.tag=my-repository:9090/root/image-name
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-16
          • 1970-01-01
          • 2019-07-30
          • 1970-01-01
          • 2016-08-28
          • 2016-02-08
          相关资源
          最近更新 更多