1:修改docker配置文件docker.service
vi /usr/lib/systemd/system/docker.service
2:找到 ExecStart,在最后面添加 -H tcp://0.0.0.0:2375
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
3:开放系统端口
3-1:关闭防火墙
systemctl stop firewalld
3-2:防火墙开放端口
添加 --permanent永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=2375/tcp --permanent
重新载入
firewall-cmd --reload
查看所有打开的端口:
firewall-cmd --zone=public --list-ports
4:重启docker
4-1:如果docker启动了执行命令
[root@localhost ~]# systemctl stop docker.socket
4-2:执行启动命令
[root@localhost ~]# systemctl daemon-reload && systemctl start docker
4-3:通过docker启动状态可以查看是否读取了配置文件和开启了监听2375端口
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2023-08-22 17:46:00 CST; 14s ago
Docs: https://docs.docker.com
Main PID: 8219 (dockerd)
Tasks: 7
Memory: 24.3M
CGroup: /system.slice/docker.service
└─8219 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.266423902+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.290199031+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.308690375+08:00" level=info msg="Loading containers: start."
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.499669329+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0...IP address"
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.527983877+08:00" level=info msg="Loading containers: done."
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.562405494+08:00" level=info msg="Docker daemon" commit=3056208 graphdriver(s)=overlay2 version=20.10.21
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.562786361+08:00" level=info msg="Daemon has completed initialization"
8月 22 17:46:00 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.601480387+08:00" level=info msg="API listen on /var/run/docker.sock"
8月 22 17:46:00 localhost.localdomain dockerd[8219]: time="2023-08-22T17:46:00.602129704+08:00" level=info msg="API listen on [::]:2375"
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
4-4:通过curl http://docker宿主机IP:2375/version验证是否可以远程连接docker
[root@localhost ~]# curl http://192.168.11.48:2375/version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"20.10.21","Details":{"ApiVersion":"1.41","Arch":"amd64","BuildTime":"2022-10-25T18:02:38.000000000+00ommit":"3056208","GoVersion":"go1.18.7","KernelVersion":"3.10.0-1160.el7.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.6.10","Details":{"GitCommit":"770bd0108},{"Name":"runc","Version":"1.1.4","Details":{"GitCommit":"v1.1.4-0-g5fd4c4d"}},{"Name":"docker-init","Version":"0.19.0","Details":{"GitCommit":"de40ad0"}}],"Version":"20.10.21","ApiVersion":"Commit":"3056208","GoVersion":"go1.18.7","Os":"linux","Arch":"amd64","KernelVersion":"3.10.0-1160.el7.x86_64","BuildTime":"2022-10-25T18:02:38.000000000+00:00"}
[root@localhost ~]#
5:windows如果无法远程连接Docker,需要把以下服务都启动
6:idea配置远程docker服务
1:在idea的Settings搜索输入docker(前提idea必须安装了docker插件)
2:点击docker
3:点击“+”
4:输入docker服务名字(自定义)
5:选择TCP socket然后输入tcp://docker宿主机IP:2375
6:连接docker服务状态为成功
![在这里插入图片描述](https://img-blog.csdnimg.cn/8c04fb8f529b4347acd14cf54e75b239.png