将Docker升级到 Docker版本18.09.2,在Ubuntu 18.04.2 LTS上构建6247962 后,容器内的DNS配置始终仅指向Google的DNS服务器。以前,容器中的/etc/resolv.conf
文件将包含主机的DNS配置。
文件/etc/resolv.conf
现在看起来像这样:
$ sudo docker run -it centos:6 bash
[root@459f5102cc74 /]# cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
# No DNS servers known.
nameserver 8.8.8.8
nameserver 8.8.4.4
[root@459f5102cc74 /]#
到目前为止,我发现的唯一解决方法是在/etc/docker/daemon.json
中手动配置DNS:
$ cat /etc/docker/daemon.json
{
"dns": ["10.0.0.1"],
"dns-search": ["example.org"]
}
重新启动Docker守护程序后,我看到:
$ sudo docker run -it centos:6 bash
[root@d1049c2c3d96 /]# cat /etc/resolv.conf
search example.org
nameserver 10.0.0.1
有没有办法让Docker自动获取主机的DNS配置?
(PS主机是静态配置的,即它没有使用DHCP。)