在你想加入时间戳的项目里加入以下内容,pom.xml里面 在<plugins>下面加入插件 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.4</version> <configuration> <timestampFormat>yyyyMMddHHmmss</timestampFormat>#设置时间格式 </configuration> <executions> <execution> <goals> <goal>create-timestamp</goal> </goals> </execution> </executions> <inherited>false</inherited> </plugin>
然后在docker 插件里面加入
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker.plugin.version}</version> <configuration> <forceTags>true</forceTags> #强制添加标签 <imageTags> <imageTag>${project.artifactId}:${project.version}-${timestamp}</imageTag> #强制标签的位置 </imageTags> <imageName>${docker.registry.url}/blade/${project.artifactId}:${project.version}</imageName> <dockerDirectory>${project.basedir}</dockerDirectory> <dockerHost>${docker.registry.host}</dockerHost> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <registryUrl>${docker.registry.url}</registryUrl> <serverId>${docker.registry.url}</serverId> <pushImage>true</pushImage> </configuration> </plugin>
cd 到项目里然后执行命令:mvn clean package docker:build 看效果
原文地址:https://www.cnblogs.com/sunju/p/12123563.html
时间: 2024-11-09 18:38:57