Docker搭建微服務自動部署 <架構探險之路>,讓咱們來看看如何利用spring boot 的maven插件實現代碼的自動化構建和發佈吧!java
插件配置git
<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>
複製代碼
Dockerfile文件放在resources下spring
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
複製代碼
mavendocker
編譯 > 打包 > 建立鏡像api
mvn clean package docker:build
複製代碼
推送鏡像架構
mvn docker:push
複製代碼
查看倉庫127.0.0.1:8000
app
docker images
複製代碼