首页 > 系统 > Linux教程

解决docker容器无法ping外网的问题

admin Linux教程 2022-02-10 08:42:15 docker容器   ping外网"

今天在docker搭建redis环境的时候,发现yum拉取不到资源,上不到网,报了如下错误:

http://mirrors.aliyun.com/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"
Trying other mirror.
http://mirrors.neusoft.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.neusoft.edu.cn'"
Trying other mirror.
http://mirrors.nwsuaf.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.nwsuaf.edu.cn'"
Trying other mirror.
http://mirrors.shu.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.shu.edu.cn'"
Trying other mirror.
http://mirrors.sohu.com/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.sohu.com'"
Trying other mirror.
http://mirrors.tuna.tsinghua.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.tuna.tsinghua.edu.cn'"
Trying other mirror.
http://mirrors.zju.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.zju.edu.cn'"
Trying other mirror.

测试wget

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

结果报错

unknown host mirrors.163.com

测试ping

在容器内部

ping www.baidu.com

结果还是失败

ping: unknown host www.baidu.com

多开一个终端,进入主机(不是进入容器),进行ping命令测试发现是OK的,基本可以确定是docker的问题了,而不是网络问题

解决方法

停止所有容器,重启docker

service docker restart

内容扩展

Docker容器内不能联网的6种解决方案

1.使用–net:host选项

2.使用–dns选项

3.改dns server

4.不用dnsmasq

5.重建docker0网络

6.直接在docker内修改/etc/hosts

以上就是解决docker容器无法ping外网的问题的详细内容,更多关于docker容器无法ping外网的资料请关注潘少俊衡其它相关文章!

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/jtjc/Linux/108907.html

留言与评论(共有 0 条评论)
   
验证码:

潘少俊衡

| 桂ICP备2023010378号-4

Powered By EmpireCMS

爱享小站

中德益农

谷姐神农

环亚肥料

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

感谢潘少俊衡友情技术支持