DNS not working within docker containers when host uses dnsmasq and Google's DNS server are firewalled?

后端 未结 6 1395
难免孤独
难免孤独 2020-12-24 03:09

The symptom is: the host machine has proper network access, but programs running within containers can\'t resolve DNS names (which may appear to be \"can\'t access the netwo

6条回答
  •  伪装坚强ぢ
    2020-12-24 03:48

    A brutal and unsafe solution is to avoid containerization of the network, and use the same network on the host and on the container. This is unsafe because this gives access to all the network resources of the host to the container, but if you do not need this isolation this may be acceptable.

    To do so, just add --network host to the command-line, e.g.

    $ sudo docker run -ti --network host mmoy/ubuntu-netutils /bin/bash
    root@ubuntu1604:/# ping www.example.com
    PING www.example.com (93.184.216.34) 56(84) bytes of data.
    64 bytes from 93.184.216.34: icmp_seq=1 ttl=55 time=86.5 ms
    64 bytes from 93.184.216.34: icmp_seq=2 ttl=55 time=86.5 ms
    

提交回复
热议问题