所有文件的-SNAPSHOT
一部分(附加在 Maven 部署“任务”上)将在deploy:deploy
阶段被时间戳版本替换。
1)创建Docker镜像文件
docker-maven-plugin
使用(由https://github.com/spotify/docker-maven-plugin上的 spotify 提供)扩展工件 POM 。
[...]
您还可以将构建目标绑定到 package 阶段,因此仅在运行 mvn package 时将构建容器。
[...]
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<imageName>${project.build.finalName}</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Docker 映像名称将定义在<imageName />
并使用工件文件名 ( ${project.build.finalName}
)。
imageName:构建的图像将被赋予此名称。
有关build
目标的更多信息:mvn com.spotify:docker-maven-plugin:help -Ddetail=true -Dgoal=build
或https://github.com/spotify/docker-maven-plugin
2) 在 Maven 部署任务上附加 Docker 镜像文件
附加 - 如果docker-maven-plugin
不为您执行 - 带有build-helper-maven-plugin
( http://www.mojohaus.org/build-helper-maven-plugin/usage.html ) 的 Docker 映像文件。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.finalName}</file>
<type>...</type>
<classifier>docker</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
在这些步骤之后,工件文件本身和 Docker 映像工件被部署到具有相同版本字符串的 Maven 存储库。