Solve the problem of docker access reporting 127.0.0.1:2375 Connection refused (Connection refused) in Linux server

Solve the problem:

org.apache.hc.client5.http.HttpHostConnectException: Connect to http://127.0.0.1:2375 [/127.0.0.1] failed: 拒绝连接 (Connection refused)

Solutions:

In a Linux server, Docker is accessed remotely, so port 2375 needs to be opened. Simply opening port 2375 on the firewall is not enough.

How to operate:

1. Query docker service

systemctl status docker.service

Insert image description here
As shown in the red box in the figure, my docker service file is stored in the /usr/lib/systemd/system/ directory.

2. Edit the docker.service service file

vim /usr/lib/systemd/system/docker.service

Append the following content after the ExecStart line

-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

Insert image description here

3. Restart the service

systemctl daemon-reload
systemctl restart docker.service

4. Check whether the port is open

netstat -nlpt

Insert image description here

at last

If the server firewall is turned on, you still need to open the port.

# 开启防火墙
service firewalld start

# 查看防火墙状态
systemctl status firewalld

# 查看所有放行端口
firewall-cmd --list-all

# 放开xxxx端口
firewall-cmd --add-port=xxxx/tcp --permanent

# 加载设置
firewall-cmd --reload

Guess you like

Origin blog.csdn.net/chengsw1993/article/details/133295095
Recommended