1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Ignore "no such file" error when docker cannot find resolv.conf

`/etc/resolv.conf` is not an essential file in filesystem. (see
http://man7.org/linux/man-pages/man5/resolv.conf.5.html)

> If this file does not exist, only the name server on the local machine
> will be queried

It's baffling to users that containers can start with an empty
`resolv.conf` but cannot without this file.

This PR:
* ignore this error and use default servers for containers in `bridge`
  mode networking.
* create an empty resolv.conf in `/var/lib/docker/containers/<id>` in
  `host` mode networking.

Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
This commit is contained in:
Yuanhong Peng 2017-08-04 12:13:14 +08:00
parent 07354ab656
commit 10c88fc3ab

View file

@ -197,14 +197,26 @@ func (sb *sandbox) setupDNS() error {
// This is for the host mode networking
if sb.config.originResolvConfPath != "" {
if err := copyFile(sb.config.originResolvConfPath, sb.config.resolvConfPath); err != nil {
return fmt.Errorf("could not copy source resolv.conf file %s to %s: %v", sb.config.originResolvConfPath, sb.config.resolvConfPath, err)
if !os.IsNotExist(err) {
return fmt.Errorf("could not copy source resolv.conf file %s to %s: %v", sb.config.originResolvConfPath, sb.config.resolvConfPath, err)
}
logrus.Infof("%s does not exist, we create an empty resolv.conf for container", sb.config.originResolvConfPath)
if err := createFile(sb.config.resolvConfPath); err != nil {
return err
}
}
return nil
}
currRC, err := resolvconf.Get()
if err != nil {
return err
if !os.IsNotExist(err) {
return err
}
// it's ok to continue if /etc/resolv.conf doesn't exist, default resolvers (Google's Public DNS)
// will be used
currRC = &resolvconf.File{}
logrus.Infof("/etc/resolv.conf does not exist")
}
if len(sb.config.dnsList) > 0 || len(sb.config.dnsSearchList) > 0 || len(sb.config.dnsOptionsList) > 0 {