使用dockerfile-maven-plugin标记创build的图像

我正在使用dockerfile-maven-plugin和以下configuration:

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

根据构build目标(与推送目标类似的方式)在存储库前加固解决了这个问题。 但是,然后本地创build的映像与储存库标记的前缀。

在推送任务之前没有find有关如何执行标签的任何文档参考。

换句话说,我希望我的本地泊坞窗图像在插件执行后将包含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

添加额外的执行步骤到我的configuration解决了这个问题:

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

您可以在问题331中看到一个configuration,您应该能够在docker build指定要应用的标记:

 <configuration> <serverId>[repo-hostname]</serverId> <registryUrl>https://[repo-hostname]:[repo-port]</registryUrl> <imageName>[repo-hostname]:[repo-port]/xxx/yyy</imageName> <dockerDirectory>${basedir}/src/docker</dockerDirectory> <imageTags> <imageTag>${project.version}</imageTag> <imageTag>latest</imageTag> <==== replace that </imageTags> </configuration> 

如问题262所述 ,您还需要:

 docker:build -DpushImage -DpushImageTags