The host can ping the external network, but the docker container cannot ping the external network; the host can use wget to download, but the docker container cannot use wget to download

The host can ping the external network, but the docker container cannot ping the external network; the host can use wget to download, but the docker container cannot use wget to download

Problem Description

1. The host machine can ping the external network, but the docker container cannot ping the external network

ping www.baidu.com

Error message:

unknown host baidu.com

2. The host can be downloaded with wget, but the docker container cannot be downloaded with wget

wget www.baidu.com

Error message:

unknown host baidu.com

Solution

szZack's article
1. Stop all containers

docker stop $(docker ps -a -q)

2. Restart docker

service docker restart

Or (Ubuntu/CentOS system):

sudo service docker restart

test

1. Enter the container
2. Ping Baidu

ping www.baidu.com

The following results are output to indicate normal operation:

abc:~$ ping www.baidu.com
PING www.baidu.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=55 time=4.42 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=2 ttl=55 time=4.32 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=3 ttl=55 time=4.43 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=55 time=4.40 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=5 ttl=55 time=4.42 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=6 ttl=55 time=4.40 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=7 ttl=55 time=4.39 ms

Articles by szZack

Common Container Operations Commands

#  docker启动 
systemctl start docker 
service docker start

#  重启docker服务
systemctl restart  docker
service docker restart

#  关闭docker  服务
systemctl stop docker
service docker stop

#  查看是否启动成功
docker ps -a

# 查看所有正在运行容器
docker ps 

# 停止容器 containerId  (containerId 是容器的ID)
docker stop containerId

# 查看所有容器
docker ps -a 

# 查看所有容器ID
docker ps -a -q 

#  stop停止所有容器
docker stop $(docker ps -a -q) 

#  remove删除所有容器
docker  rm $(docker ps -a -q)  

Articles by szZack

Guess you like

Origin blog.csdn.net/zengNLP/article/details/126732645