首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用dockerfile-maven-plugin标记创建的映像

用dockerfile-maven-plugin标记创建的映像
EN

Stack Overflow用户
提问于 2017-11-05 10:06:38
回答 3查看 7.5K关注 0票数 2

我使用的是dockerfile-maven-plugin,配置如下:

代码语言:javascript
运行
复制
  <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>

由于以下原因,项目部署失败:

代码语言:javascript
运行
复制
[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
.
.
.

在构建目标下对存储库进行前缀(类似于推动目标)解决了这个问题。但是,本地创建的映像以存储库标记为前缀。

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

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

代码语言:javascript
运行
复制
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

我的码头版本是: 17.06.0-ce

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-05 10:56:06

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

代码语言:javascript
运行
复制
<execution>
    <id>tag-image</id>
    <phase>deploy</phase>
    <goals>
        <goal>tag</goal>
    </goals>
    <configuration>
        <repository>${docker.registry.url}/root/${project.artifactId}</repository>
    </configuration>
</execution>
票数 2
EN

Stack Overflow用户

发布于 2018-12-04 13:49:34

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

代码语言:javascript
运行
复制
<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>
票数 3
EN

Stack Overflow用户

发布于 2018-07-19 07:48:46

您还可以在成功构建之后将映像标记为

代码语言:javascript
运行
复制
mvn dockerfile:tag -Dproject.plugin.dockerfile.tag=my-repository:9090/root/image-name
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47120324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档