问题
I have the fabric8 docker-maven-plugin configured in my pom.xml as follows:
<build>
...
<plugins>
...
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<images>
<image>
<name>${docker.image.prefix}/${project.artifactId}:%l</name>
<build>
<dockerFile>Dockerfile</dockerFile>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
...
</plugins>
...
</build>
I'm using the %l
placeholder which tags the image with the latest
label if the version contains -SNAPSHOT
, otherwise it uses the pom version.
When building from CI, I'd like to include some additional tags (possibly more then one) to my image (e.g. build number / branch name) but I'd like to keep %l
placeholder behavior.
I think that it should be possible using maven properties from command line, but I couldn't figure it out from the plugin docs (https://dmp.fabric8.io/)
How can I include additional tags when executing the docker:build goal?
回答1:
You can use the <tags>
tag:
https://dmp.fabric8.io/#build-configuration
<properties>
...
<!-- set default -->
<docker.image-tag>${project.version}</docker.image-tag>
...
</properties>
<image>
...
<name>repo/something/%a:%l</name>
<build>
...
<tags>
<tag>${docker.image-tag}</tag>
</tags>
...
</build>
...
</image>
this will tag your image with both the %l
behavior and the custom set ${docker.image-tag}
.
mvn docker:build -Ddocker.image-tag=mytag
来源:https://stackoverflow.com/questions/44554857/fabric8-docker-maven-plugin-include-additional-tags-on-build