zoukankan      html  css  js  c++  java
  • [转]Docker容器内不能联网的6种解决方案

    注:

    下面的方法是在容器内能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
    
  • 相关阅读:
    git command
    MySQL命令行学习
    添加react-router
    nodejs 安装出错总结
    切换分支之后,意外出现的,待提交的改变
    git diff
    git log
    搜索的技巧
    x-shell code
    css汇总
  • 原文地址:https://www.cnblogs.com/everfight/p/docker_connect_net.html
Copyright © 2011-2022 走看看