Docker容器内不能联网的6种解决方案
Docker容器内不能联网的6种解决方案
注:下面的方法是在容器内能ping通公网IP的解决方案,如果连公网IP都ping不通,那主机可能也上不了网(尝试ping8.8.8.8)
1.使用–net:host选项
sudodockerrun--net:host--nameubuntu_bash-i-tubuntu:latest/bin/bash
2.使用–dns选项
sudodockerrun--dns8.8.8.8--dns8.8.4.4--nameubuntu_bash-i-tubuntu:latest/bin/bash
3.改dnsserver
vi/etc/default/docker
去掉“docker_OPTS="–dns8.8.8.8--dns8.8.4.4"”前的#号
4.不用dnsmasq
vi/etc/NetworkManager/NetworkManager.conf
在dns=dnsmasq前加个#号注释掉
sudorestartnetwork-manager sudorestartdocker
5.重建docker0网络
pkilldocker#终止进程 iptables-tnat-F#清空nat表的所有链 ifconfigdocker0down#停止docker默认网桥 brctldelbrdocker0#删除网桥 docker-d
6.直接在docker内修改/etc/hosts
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。如果你想了解更多相关内容请查看下面相关链接