我的 docker 中的 DNS 配置错误是什么?

我的 docker 中的 DNS 配置错误是什么?

我最近在我的 ubuntu 16.04 上安装了 docker。我成功拉取并运行了 hello-world、ubuntu 和 sinatra 镜像,但我认为它们无法连接到互联网!!

例如抛出了以下错误

1. 在 ubuntu 镜像中:

 ali@ali-Satellite-M645:~$ sudo docker run ubuntu apt-get update


  Err:1 `http://archive.ubuntu.com/ubuntu xenial InRelease`
   Temporary failure resolving 'archive.ubuntu.com'

 Err:2 `http://archive.ubuntu.com/ubuntu xenial-updates` InRelease
  Temporary failure resolving 'archive.ubuntu.com'

 Err:3 `http://archive.ubuntu.com/ubuntu xenial-security` InRelease
  Temporary failure resolving 'archive.ubuntu.com'

 Reading package lists...

 W: Failed to fetch `http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease`  Temporary failure resolving 'archive.ubuntu.com'

 W: Failed to fetch `http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease`  Temporary failure resolving 'archive.ubuntu.com'

 W: Failed to fetch `http://archive.ubuntu.com/ubuntu/dists/xenial-security/InRelease`  Temporary failure resolving 'archive.ubuntu.com'

 W: Some index files failed to download. They have been ignored, or old ones used instead.

2. 这是 sinatra 上的

   ali@ali-Satellite-M645:~$ docker run -i -t  training/sinatra


   root@fd5c3656dd0b:/# ping google.com
   ping: unknown host google.com
   root@fd5c3656dd0b:/# 

所以我在谷歌上搜索了这个问题,人们正在谈论DNS 配置问题导致图像无法解析域名。

解决此类问题的方法是编辑文件 /etc/default/docker 并输入正确可用的 DNS ip,如下所示:

  1. 使用网络管理器获取 DNS IP:

    nmcli dev show | grep DNS | sed 's/\s\s*/\t/g' | cut -f 2
    

获取 DNS IP:10.10.10.11 和 10.10.10.10

  1. 编辑文件如下:

      # Docker Upstart and SysVinit configuration file  
      #
      # THIS FILE DOES NOT APPLY TO SYSTEMD
      #
      #   Please see the documentation for "systemd drop-ins":
      #   https://docs.docker.com/engine/articles/systemd/
    
      # Customize location of Docker binary (especially for development testing).
      #DOCKER="/usr/local/bin/docker"
      # Use DOCKER_OPTS to modify the daemon startup options.
      DOCKER_OPTS="--dns 10.10.10.11 --dns 10.10.10.10 --dns 8.8.8.8"
    
      # If you need Docker to use an HTTP proxy, it can also be  specified here.
      #export http_proxy="http://127.0.0.1:3128/"
    
      # This is also a handy place to tweak where Docker's temporary files go.
      #export TMPDIR="/mnt/bigdrive/docker-tmp"
    
  2. 重启 Docker

       sudo service docker restart
    
  3. 在 ubuntu 镜像上重试 apt-get 更新并 ping google.com,仍然抛出同样的错误

对于这个问题有什么想法吗?

谢谢。

相关内容