Docker容器不能解析DNS本地地址
ErrorcodeStep 2/9 : RUN apt-get update&& apt-get install --no-install-recommends --no-install-suggests -ysupervisoropenssh-server&& echo "root:Docker!" | chpasswd---> Running in
·
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
更多推荐
已为社区贡献2条内容
所有评论(0)