Jenkins构建部署
插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>${project.artifactId}</imageName>
<imageTags>${project.version}</imageTags>
<dockerDirectory>./</dockerDirectory>
</configuration>
</plugin>
</plugins>
</build>
imageName: 构建的image名字,重要
imageTags: 标签
Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /temp
EXPOSE 8080
ARG JAR_FILE=target/test-1.0-SNAPSHOT.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]
- 8080: 暴漏接口
- target/test-1.0-SNAPSHOT.jar : 打包之后的jar位置,相对pom的路径
Jenkins maven build 参数
clean package docker:build
build之后的执行命令
docker stop test;
docker rm test;
docker images|grep -n '<none>'|awk '{print $3}'|tr "\n" " " | xargs docker rmi;
docker run -d -p 8080:8080 --name test test:latest
- test:镜像名
- 停止当前容器
- 删除旧的容器
- 运行最新的镜像,镜像叫 test, tag latest 容器叫 test