您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何解決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外網的問題”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。