如何使用Maven在Windows机器上创buildDockerfile,然后发送到远程Linux服务器来构build映像,然后运行?

我有一个用Maven构build的Java项目。 我想在构build时dynamic创build一个Dockerfile。 我的最终目标是创build一个可执行的Jar和Dockerfile,将它们都发送到服务器,在Dockerfile中使用Dockerfile来构build将执行Jar的映像,然后运行容器。 这将主要用于构build/testing过程,所以我不想在每次testing之前提交任何代码或将我的Jar发布到Artifactory。 我觉得4个独立的authentication服务器是非常低效的。 我试图find一个Maven插件,可以做到这一切,但没有任何运气。 有没有一个插件可以为我做这一切,或只是一个比我目前做的更好的方式? 提前致谢。 如果有的话,我会将答案标记为有用的,并将标记为正确的答案。 提前致谢! 以下是我目前Maven插件的工作进展情况。

<!--This plugin will Transfer the executable JAR and Dockerfile file to a remote server, build an image and run it --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <phase>install</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!-- Create a Docerfile --> <echo file="${project.build.directory}/Dockerfile.txt" message="FROM java:8${line.separator}" append="true"/> <echo file="${project.build.directory}/Dockerfile.txt" message="ADD ${pi.deployDirectory}/${project.build.finalName}-jar-with-dependencies.jar ${pi.deployDirectory}/demo/${project.build.finalName}-jar-with-dependencies.jar${line.separator}" append="true"/> <echo file="${project.build.directory}/Dockerfile.txt" message="CMD [&quot;java&quot;,&quot;-jar&quot;,&quot;${pi.deployDirectory}/demo/${project.build.finalName}-jar-with-dependencies.jar&quot;]" append="true"/> <!-- ensure the target directory exists on the Server --> <sshexec host="${server.host}" port="${server.port}" username="${server.user}" password="${server.password}" trust="true" failonerror="false" verbose="true" command="mkdir --parents ${server.deployDirectory}"/> <!-- copy the JAR file to the Server --> <scp file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar" todir="${server.user}:${server.password}@${server.host}:${server.deployDirectory}" port="${server.port}" trust="true" verbose="true" failonerror="true"> </scp> <!-- copy the Dockerfile file to the Server --> <scp file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar" todir="${server.user}:${server.password}@${server.host}:${server.deployDirectory}" port="${server.port}" trust="true" verbose="true" failonerror="true"> </scp> <!-- TODO: Add section that will on the remote server build a container using the new Dockerfile and then run that container --> <!-- run the JAR file on the Server no in container--> <sshexec host="${server.host}" port="${server.port}" username="${server.user}" password="${server.password}" trust="true" failonerror="false" verbose="true" command="java -jar ${server.deployDirectory}/${project.build.finalName}-jar-with-dependencies.jar"/> </tasks> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant-jsch</artifactId> <version>1.9.6</version> </dependency> </dependencies> </plugin>