1.修改宿主机docker配置文件,让其可远程访问:在配置文件中ExecStart=后添加配置‐H tcp://0.0.0.0:2375 ‐H unix:///var/run/docker.sock
vi /lib/systemd/system/docker.service
2.刷新配置,重启服务
systemctl daemon‐reload
systemctl restart docker
docker start registry
3.以上docker和docker镜像仓库registry已经准备好了,在项目的pom文件中增加插件:
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- docker的maven插件,官网:
https://github.com/spotify/docker‐maven‐plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>192.168.245.136:5000/${project.artifactId}:${project.version}
</imageName>
<baseImage>jdk1.8</baseImage>
<entryPoint>["java", "-jar", cd ."/${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.245.136:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
dockerHost 是docker的地址
imageName 是docker仓库的地址
4.打开终端,到项目pom文件所在位置,输入:
mvn clean package docker:build ‐DpushImage
5.访问镜像仓库
http://192.168.245.136:5000/v2/_catalog 可以看到对应的镜像
打开docker image 可以看到docker上对应的镜像。