1、配置Docker远程连接端口
vi /usr/lib/systemd/system/docker.service
#找到ExecStar 在后面添加
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
重启Docker
systemctl daemon-reload
systemctl restart docker
systemctl status docker
防火墙添加2375端口
systemctl status firewalld
#启动防火墙 没有提示
systemctl start firewalld
#添加2375端口
firewall-cmd --permanent --zone=public --add-port=2375/tcp
#防火墙重启
firewall-cmd --reload
#查看开放的端口
firewall-cmd --permanent --zone=public --list-ports
2、搭建项目,配置docker插件

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.3</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
<properties>
<docker.image.prefix>yi</docker.image.prefix>
</properties>
Dockerfile文件
# Docker image for springboot file run
# VERSION 0.0.1
# Author: yi
# 基础镜像使用java
FROM java:8
# 作者
MAINTAINER yi <yi@gmail.com>
# VOLUME 指定了临时文件目录为/tmp。
# 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为app.jar
ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar
# 运行jar包
#RUN bash -c 'touch /app.jar'
#执行项目 app.jar。为了缩短 Tomcat 启动时间,添加一个系统属性指向 “/dev/./urandom” 作为 Entropy Source
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
打包
mvn package
拷贝eureka-server-0.0.1-SNAPSHOT.jar 至docker包下
3、idea安装Docker插件并配置连接Docker
输入远程主机的 ip 加端口:2375
name:本地docker名称
Dockrfile:选中Dockfile文件的路径
Image tag:镜像名称+版本号
Containner name:容器名称
Bind Port :映射端口号
启动docker-eureka
浏览器访问,服务正常
http://xxx.xxx.xx.131:8761/
4、Docker暴露2375端口,引起安全漏洞
启动Docker Daemon时,加入-H 0.0.0.0:2375,Docker Daemon就可以接收远端的Docker Client发送的指令。注意,Docker是把2375端口作为非加密端口暴露出来,一般是用在测试环境中。此时,没有任何加密和认证过程,只要知道Docker主机的IP,任何人都可以管理这台主机上的容器和镜像。
如何修复该漏洞
Docker本身提供了加密的远程管理端口2376,配合CA证书,就能提供TLS连接了,可以安全的管理远程Docker主机。