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.刷新配置,重启服务
systemctl daemon-reload
systemctl restart docker
docker start registry
验证是否配置成功,访问“http://192.168.26.130:2375/info”,有json数据,说明成功了。
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.进入项目根目录,执行下面命令
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