1、vi /lib/systemd/system/docker.service
2、修改

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
3、systemctl daemon-reload
4、 systemctl restart docker
5、检查2375端口:netstat -nlpt

6、本地验证接口是否可访问docker:curl http://192.168.150.130:2375/info

7、关闭防火墙,或开放指定2375端口开放
firewall-cmd --zone=public --add-port=2375/tcp --permanent
8、重启防火墙:
firewall-cmd --reload
(补:查看哪些端口开放防火墙: firewall-cmd --list-ports)
9、idea上进行配置:


10、pom.xml配置docker
参考:https://www.cnblogs.com/jpfss/p/10945324.html
我使用的方式:
<plugins>
<!-- springboot打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<!-- 镜像名称 -->
<imageName>${docker.image.prefix}/${project.name}</imageName>
<!-- 标签-->
<imageTags>
<imageTag>lastest</imageTag>
</imageTags>
<!-- 基础镜像-->
<baseImage>java</baseImage>
<!-- 制作人信息-->
<maintainer>lidan@360.cn</maintainer>
<!-- 切换到root目录-->
<workdir>/ROOT</workdir>
<cmd>["java","-version"]</cmd>
<entryPoint>["java","-jar","${project.build.finalName}.jar"]</entryPoint>
<!-- docker远程服务器地址 -->
<dockerHost>http://192.168.150.130:2375</dockerHost>
<!-- Dockerfile文件存放目录 -->
<!-- <dockerDirectory>src\main\docker</dockerDirectory>-->
<resources>
<resource>
<targetPath>/ROOT</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
注:dockerDirectory的方式和pom.xml配置dockerfile关键词的方式,二选一
11、maven打包:mvn clean package docker:build
12、部署容器:



网友评论