Home > Article > Operation and Maintenance > Docker cannot connect to the external network solution
Docker cannot connect to the external network Solution:
1. If it has been used normally before, and then the host can access the external network, but the container cannot, you can Try restarting the docker service to solve the problem:
>>>sercice docker restart #debian/ubutun中sh为dash,centos指bash >>>docker run -it -v /yourfile:/file -p 8000:8000 /bin/bash imageid >>>
2. The docker container provides services and listens to port 8888. To enable external access, port mapping is required.
docker run -it --rm -p 8888:8888 server:v1
A problem occurs at this time. After deployment on virtual machine A, the 8888 port service can be accessed in A, but cannot be accessed in B.
This should be due to the request being intercepted.
Check firewall-cmd --state
If the output is "not running", FirewallD is not running, and all protection strategies are not started, then you can Rule out the firewall blocking the connection.
If the output is "running", it means that FirewallD is currently running. You need to enter the following command to see which ports and services are now open:
firewall-cmd --list-ports firewall-cmd --list-services
There are two solutions:
1. Turn off the FirewallD service:
If you don’t need a firewall, just turn off the FirewallD service directly
systemctl stop firewalld.service
2. Add a policy to open the specified port to the outside world:
For example, if we want to open the external 5000/tcp port now, we can use the following command:
firewall-cmd --add-port=5000/tcp --permanent firewall-cmd --reload
If we only temporarily open the port, remove the "--permanent" parameter in the first line of the command, then when This policy will become invalid when the FirewallD service is restarted again.
ip forwarding is not turned on
sysctl net.ipv4.ip_forward
If net.ipv4.ip_forward=0 is displayed, it means it is not turned on.
Open the sysctl.conf file
vi /etc/sysctl.conf
Add the following code:
net.ipv4.ip_forward=1
For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.
The above is the detailed content of Docker cannot connect to the external network solution. For more information, please follow other related articles on the PHP Chinese website!