Tagging created image with dockerfile-maven-plugin Tagging created image with dockerfile-maven-plugin docker docker

Tagging created image with dockerfile-maven-plugin


We didn't want to build all over again even if existing docker layers would be used. In the first execution we build and push and in the second execution we just tag and push.

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


Adding additional execution step to my configuration solved the issue:

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


You can also tag your image manually after a successful build with

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