Docker容器不能解析DNS本地地址

Containers cannot resolve DNS if docker host uses 127.0.0.1 as resolver

Error code

Step 2/9 : RUN apt-get update     && apt-get install --no-install-recommends --no-install-suggests -y     supervisor     openssh-server     && echo "root:Docker!" | chpasswd
 ---> Running in 622924bc162e
Err:1 http://security.debian.org stretch/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:2 http://deb.debian.org/debian stretch InRelease
  Temporary failure resolving 'deb.debian.org'
Err:3 http://nginx.org/packages/mainline/debian stretch InRelease
  Temporary failure resolving 'nginx.org'
Err:4 http://deb.debian.org/debian stretch-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/dists/stretch/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://nginx.org/packages/mainline/debian/dists/stretch/InRelease  Temporary failure resolving 'nginx.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package supervisor
E: Unable to locate package openssh-server

Solve

reason

default DNS server can not resolve domain name to IP.
default DNS file: /etc/resolv.conf

root@song-Virtual-Machine:/etc# cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search corp.microsoft.com

get actual DNS server

Get/Set DNS server

$ cat /etc/resolv.conf | grep nameserver  # What Docker sees
nameserver 127.0.1.1
$ nmcli dev show | grep IP4.DNS  # My actual DNS server
IP4.DNS[1]:                             10.50.50.50

Fail Info

song@song-Virtual-Machine:~/git/apps/nginx$ docker run busybox nslookup corp.microsoft.com
Server:    8.8.8.8
Address 1: 8.8.8.8

nslookup: can't resolve 'corp.microsoft.com'

Edit resolve.conf with actual dns server

root@song-Virtual-Machine:/etc# cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
#nameserver 127.0.1.1
nameserver 10.50.50.50
search corp.microsoft.com

Resolve successfully.

song@song-Virtual-Machine:~/git/apps/nginx$ docker run busybox nslookup corp.microsoft.com
Server:    10.50.50.50
Address 1: 10.50.50.50 f5-1.redmond.corp.microsoft.com

Name:      corp.microsoft.com
...

Context

root@song-Virtual-Machine:/etc# docker version
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:42:18 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:56 2017
 OS/Arch:      linux/amd64
 Experimental: false
root@song-Virtual-Machine:/etc# cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值