插件
<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