注:

下面的方法是在容器内能ping通公网IP的解决方案,如果连公网IP都ping不通,那主机可能也上不了网(尝试ping 8.8.8.8)

1.使用--net:host选项
sudo docker run --net:host --name ubuntu_bash -i -t ubuntu:latest /bin/bash


2.使用--dns选项
sudo docker run --dns 8.8.8.8 --dns 8.8.4.4 --name ubuntu_bash -i -t ubuntu:latest /bin/bash


3.改dns server
vi /etc/default/docker
去掉“docker_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"”前的#号


4.不用dnsmasq
vi /etc/NetworkManager/NetworkManager.conf 
在dns=dnsmasq前加个#号注释掉

sudo restart network-manager
sudo restart docker

 
5.重建docker0网络
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d


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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-05-14
  • 2021-11-25
  • 2021-11-21
相关资源
相似解决方案