docker maven插件使用首先要docker可以远程访问
- 修改宿主机的docker配置,让其支持远程访问。
vi /lib/systemd/system/docker.service
其中ExecStart=后添加配置-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
复制代码
修改过如下图:
systemctl daemon-reload
systemctl restart docker
复制代码
- 在项目pom中加入docker的maven插件支持
<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.188.188:5000/${project.artifactId}:${project.version}</imageName>
<baseImage>java8</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.188.188:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
复制代码
以上配置会自动生成Dockerfile
FROM java8
ADD app.jar /
ENTRYPOINT ["java","-jar","/app.jar"]
复制代码