背景

1.国外VPS
2.centos:latest镜像,(docker pull centos获取)
3.docker run -it centos:latest /bin/bash进入容器后无法利用yum安装各种软件,同时能够ping得通其他的公网IP(比如DNS:8.8.8.8),但是无法ping的通域名。
提示错误:

[root@134cb8642a4e /]# yum search vim
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                                                                                                                                                  0.0  B/s |   0  B     01:00    
Errors during downloading metadata for repository 'appstream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
[root@134cb8642a4e /]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
[root@134cb8642a4e /]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=49 time=33.8 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=49 time=33.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=49 time=33.7 ms

解决办法

增加防火墙的放行规则(我这里利用firewall-cmd对防火墙进行控制)

firewall-cmd --zone=public  --add-masquerade  --permanent #允许防火墙伪装IP
firewall-cmd --reload #重启防火墙使之生效
systemctl restart docker #重启docker服务
docker container ps -a #找出自己的dockerid,重新进入

此时发现yum可以用了,也可以ping的通域名了。

[root@134cb8642a4e /]# ping www.google.com
PING www.google.com (172.217.14.196) 56(84) bytes of data.
64 bytes from sea30s01-in-f4.1e100.net (172.217.14.196): icmp_seq=1 ttl=115 time=1.97 ms
64 bytes from sea30s01-in-f4.1e100.net (172.217.14.196): icmp_seq=2 ttl=115 time=1.14 ms
64 bytes from sea30s01-in-f4.1e100.net (172.217.14.196): icmp_seq=3 ttl=115 time=1.84 ms
64 bytes from sea30s01-in-f4.1e100.net (172.217.14.196): icmp_seq=4 ttl=115 time=4.05 ms


[root@134cb8642a4e /]# yum search docker
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:20:49 ago on Fri Dec 18 02:09:29 2020.
====================================================================================== Name & Summary Matched: docker ======================================================================================
pcp-pmda-docker.x86_64 : Performance Co-Pilot (PCP) metrics from the Docker daemon
podman-docker.noarch : Emulate Docker CLI using podman

尝试过的办法

1.更改/etc/resolv.conf:添加新的DNS服务器地址,原来为8.8.8.8和8.8.4.4(这两个是国外的DNS),添加114.114.114.114(这个是国内的DNS)。

希望帮到你!_

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐