1、Docker服务开启TCP端口:
1、服务器开启TCP端口
192.168.43.23 k8s-master
环境:CentOS Linux release 7.8.2003 (Core)
$ vi /lib/systemd/system/docker.service
注释原有的:
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
添加新的:
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
# 重新加载系统服务配置文件(包含刚刚修改的文件)
$ systemctl daemon-reload
# 重启docker服务
$ systemctl restart docker
# 查看端口是否被docker监听
$ ss -tnl | grep 2375
# 查看端口是否开启
$ netstat -nlpt
# 查看防火墙是否开放2375端口(防火墙未开启则无需开放)
$ firewall-cmd --zone=public --query-port=2375/tcp
# 防火墙添加开放2375端口
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重启防火墙
$ firewall-cmd --reload
# 验证:直接curl看是否生效
$ curl http://127.0.0.1:2375/info
# 虚拟机配置好之后,本机的window上,telnet测试:
$ telnet 192.168.43.23 2375
2、Idea中配置Docker
1)安装 Docker integration 插件
File->Settings->Plugins ,安装后重启idea
2)配置 Docker
File->Settings->Build,Execution,Deployment->Docker
选择 TCP socket,Engine API URL设置为: tcp://192.168.43.23:2375
直到下方出现 Connection successful
3)修改pom文件
<properties>
<springboot.version>2.4.2</springboot.version>
<docker.image.prefix>chenchg</docker.image.prefix>
</properties>
<build><plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<!-- made of '[a-z0-9-_.]' eg: chenchg/dkdemo:1.1.0-->
<imageName>${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
<dockerDirectory>${project.basedir}</dockerDirectory>
<dockerHost>http://192.168.43.23:2375</dockerHost>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
...
</plugins></build>
- 项目根目录配置Dockerfile
根目录对应plugin中的dockerDirectory配置:${project.basedir}
FROM java:8
VOLUME /tmp
COPY target/demo-0.0.1-SNAPSHOT.jar demo.jar
RUN bash -c “touch /demo.jar”
EXPOSE 8080
ENTRYPOINT [“java”,"-jar",“demo.jar”]