使用 docker-maven-plugin : fabric8 打包
1、本地需要安装 Docker Desktop
另外推荐使用稳定标准的镜像,比如:adoptopenjdk/openjdk11
2、然后在 pom.xml 增加镜像打包的 maven 插件配置。
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.39.1</version>
<configuration>
<images>
<image>
<name>${project.artifactId}:latest</name>
<build>
<from>adoptopenjdk:openjdk11</from>
<entryPoint>
<arg>java</arg>
<arg>-jar</arg>
<arg>/${project.build.finalName}.jar</arg>
<arg>--server.port=8080</arg>
<arg>--drift=1</arg>
</entryPoint>
<assembly>
<inline>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<destName>${project.build.finalName}.jar</destName>
</file>
</files>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
3、完成正常 jar 打胖包
4、运行插件的:"docker:build" 命令之后,就会进入本地仓库了。
发布到中央仓库或别的远程仓库。发布前,还需要注册账号(这个网上搜索下)。
docker tag demoapp:latest noearorg/demoapp:latest
docker push noearorg/demoapp:latest
docker tag demoapp:latest noearorg/demoapp:1.0.0
docker push noearorg/demoapp:1.0.0
之后是运行:
#第一次运行
docker run -d -p 8080:8080 demoapp
#之后
docker restart demoapp
docker stop demoapp