> /etc/sysctl .conf" to modify the configuration and enable the ipv4 forwarding function of the host."/> > /etc/sysctl .conf" to modify the configuration and enable the ipv4 forwarding function of the host.">

Home  >  Article  >  Operation and Maintenance  >  What should I do if docker cannot access the external network?

What should I do if docker cannot access the external network?

WBOY
WBOYOriginal
2022-08-16 17:22:2914680browse

There are two solutions for docker unable to access the external network: 1. Use "service docker stop", "pkill docker" and other operations to rebuild the network docker0; 2. Use "echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf" modify the configuration and enable the host's ipv4 forwarding function.

What should I do if docker cannot access the external network?

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What should I do if docker cannot access the external network?

1. Problem

The host machine can access the external network normally, but it cannot be accessed from the container created by docker External network

What should I do if docker cannot access the external network?

2. Solution

Method 1: Rebuild the networkdocker0

sudo service docker stop
sudo pkill docker
sudo iptables -t nat -F
sudo ifconfig docker0 down
sudo brctl delbr docker0
sudo service docker start

What should I do if docker cannot access the external network?

Method 2: Enable the host’s ipv4 forwarding function

# 修改配置
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

# 重启network
systemctl restart network

# 查看 (0->标识未开启 1->标识开启)
sysctl net.ipv4.ip_forward
# net.ipv4.ip_forward = 1

# 重启docker
systemctl restart docker

Recommended study: "docker video tutorial

The above is the detailed content of What should I do if docker cannot access the external network?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn