Docker搭建微服務自動部署 <架構探險之路>,讓我們來看看如何利用spring boot 的maven外掛實現程式碼的自動化構建和釋出吧!
Docker 之 Spring Boot 自動化部署
spring-boot-maven-plugin
外掛配置
<properties>
...
<!--Docker Repo-->
<docker.registry>127.0.0.1:5000</docker.registry>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<imageName>${docker.registry}/${project.groupId}/${project.artifactId}:${project.version}</imageName>
<dockerDirectory>
${project.build.outputDirectory}
</dockerDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
複製程式碼
Dockfile
Dockerfile檔案放在resources下
FROM 127.0.0.1:5000/env-jdk:1.0
MAINTAINER "xiachaoyang"<xiazhaoyang@live.com>
ADD msa-api-hello-0.0.1.jar app.jar
EXPOSE 8080
CMD java -jar app.jar
複製程式碼
maven
編譯 > 打包 > 建立映象
mvn clean package docker:build
複製程式碼
推送映象
mvn docker:push
複製程式碼
檢視倉庫127.0.0.1:8000
docker images
複製程式碼