1.修改你要部署到的宿主機的docker配置,讓其可以遠程訪問
vi /lib/systemd/system/docker.service
#找到ExecStart開頭的行,替換成下面的
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
2.刷新配置,重啟服務(wù)
systemctl daemon-reload
systemctl restart docker
docker start registry
驗證是否配置成功,訪問“http://192.168.26.130:2375/info”,有json數(shù)據(jù),說明成功了。
3.在工程pom.xml 增加配置
<build> <finalName>app</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <configuration> <!--注意:前面不能加"http://",${project.artifactId}:${project.version}的值不能有大寫--> <imageName>192.168.26.130:5000/${project.artifactId}:${project.version}</imageName> <baseImage>jdk1.8</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://192.168.26.130:2375</dockerHost> </configuration> </plugin> </plugins> </build>
4.進入項目根目錄,執(zhí)行下面命令
mvn install
5.打包和上傳鏡像
mvn docker:build -DpushImage
6.進入宿主機查看鏡像或者訪問"http://192.168.26.130:5000/v2/_catalog"
docker images
?
?7.啟動容器
docker run -di --name=fast-boot -p 9001:8081 9e6a660668b2(容器id)
?
本文摘自 :https://blog.51cto.com/u