//dockermaven
<build>
<finalName>sharedlease-1.0</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--docker的maven插件,官网:-->
<!--https://github.com/spotify/docker-maven-plugin-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>服务器ip:5000/${project.artifactId}:${project.version}</imageName>
<baseImage>ascdc/jdk8</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]
</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}
</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<dockerHost>http://服务器ip:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
~~~ssh
# ssh插件控制远程服务器执行脚本,删除容器和镜像,防止重复,当然,好像镜像是可以覆盖的。
containerId=$(docker ps -a | grep -w sir | awk '{print $1}')
if [ -n "$containerId" ];
then
docker stop $containerId
docker rm $containerId
echo "成功删除容器"
fi
imageld=$(docker images | grep -w 服务器ip:5000/sharedlease | awk '{print $3}')
if [ -n "$imageld" ];
then
docker rmi -f $imageld
echo "成功删除镜像"
fi
~~~ssh
# jenkins服务器执行代码,打包源码并推送镜像到远程服务器
mvn clean package docker:build
~~~ssh
# 远程服务器执行
docker run --name=sir -d -p 8090:8090 服务器ip:5000/sharedlease:1.0
jenkins+dockermaven部署springboot应用到远程服务器
最新推荐文章于 2023-07-13 22:07:39 发布