Repository: moby/moby
File: daemon/container_operations_unix.go (Go)

Code before:
		// the host, which may be a local DNS server (for example, if DNSMasq or
		// systemd-resolvd are in use). The embedded DNS server forwards DNS
		// resolution to the DNS server configured on the host, which in itself
		// may act as a forwarder for external DNS servers.
		// If systemd-resolvd is used, the "upstream" DNS servers can be found in
		// /run/systemd/resolve/resolv.conf. We do not query those DNS servers
		// directly, as they can be dynamically reconfigured.
		originResolvConfPath = "/etc/resolv.conf"
	default:
		// For other situations, such as the default bridge network, container
		// discovery / name resolution is handled through /etc/hosts, and no
		// embedded DNS server is available. Without the embedded DNS, we
		// cannot use local DNS servers on the host (for example, if DNSMasq or
		// systemd-resolvd is used). If systemd-resolvd is used, we try to
		// determine the external DNS servers that are used on the host.
		// This situation is not ideal, because DNS servers configured in the
		// container are not updated after the container is created, but the
		// DNS servers on the host can be dynamically updated.
		//
		// Copy the host's resolv.conf for the container (/run/systemd/resolve/resolv.conf or /etc/resolv.conf)
		originResolvConfPath = cfg.GetResolvConf()
	}

	// Allow tests to point at their own resolv.conf file. Note that
	// this only overrides the resolvConf path, not "/etc/hosts", which
	// (for containers using the "host" network namespace is set above).
	if envPath := os.Getenv("DOCKER_TEST_RESOLV_CONF_PATH"); envPath != "" {
		log.G(context.TODO()).Infof("Using OriginResolvConfPath from env: %s", envPath)
		originResolvConfPath = envPath
	}
	sboxOptions = append(sboxOptions, libnetwork.OptionOriginResolvConfPath(originResolvConfPath))

	hostsPath, err := ctr.GetRootResourcePath("hosts")
	if err != nil {
		return nil, err
	}
	resolvConfPath, err := ctr.GetRootResourcePath("resolv.conf")
	if err != nil {
		return nil, err
	}

	ctr.HostsPath, ctr.ResolvConfPath = hostsPath, resolvConfPath
	sboxOptions = append(sboxOptions,
		libnetwork.OptionHostsPath(hostsPath),
		libnetwork.OptionResolvConfPath(resolvConfPath),
	)

	return sboxOptions, nil
}

func (daemon *Daemon) initializeNetworkingPaths(ctr *container.Container, nc *container.Container) error {

Review comment (suggestion):
```suggestion
	// for containers using the "host" network namespace is set above.
```

Code after:
		// the host, which may be a local DNS server (for example, if DNSMasq or
		// systemd-resolvd are in use). The embedded DNS server forwards DNS
		// resolution to the DNS server configured on the host, which in itself
		// may act as a forwarder for external DNS servers.
		// If systemd-resolvd is used, the "upstream" DNS servers can be found in
		// /run/systemd/resolve/resolv.conf. We do not query those DNS servers
		// directly, as they can be dynamically reconfigured.
		originResolvConfPath = "/etc/resolv.conf"
	default:
		// For other situations, such as the default bridge network, container
		// discovery / name resolution is handled through /etc/hosts, and no
		// embedded DNS server is available. Without the embedded DNS, we
		// cannot use local DNS servers on the host (for example, if DNSMasq or
		// systemd-resolvd is used). If systemd-resolvd is used, we try to
		// determine the external DNS servers that are used on the host.
		// This situation is not ideal, because DNS servers configured in the
		// container are not updated after the container is created, but the
		// DNS servers on the host can be dynamically updated.
		//
		// Copy the host's resolv.conf for the container (/run/systemd/resolve/resolv.conf or /etc/resolv.conf)
		originResolvConfPath = cfg.GetResolvConf()
	}

	// Allow tests to point at their own resolv.conf file. Note that
	// this only overrides the resolvConf path, not "/etc/hosts", which
	// for containers using the "host" network namespace is set above.
	if envPath := os.Getenv("DOCKER_TEST_RESOLV_CONF_PATH"); envPath != "" {
		log.G(context.TODO()).Infof("Using OriginResolvConfPath from env: %s", envPath)
		originResolvConfPath = envPath
	}
	sboxOptions = append(sboxOptions, libnetwork.OptionOriginResolvConfPath(originResolvConfPath))

	hostsPath, err := ctr.GetRootResourcePath("hosts")
	if err != nil {
		return nil, err
	}
	resolvConfPath, err := ctr.GetRootResourcePath("resolv.conf")
	if err != nil {
		return nil, err
	}

	ctr.HostsPath, ctr.ResolvConfPath = hostsPath, resolvConfPath
	sboxOptions = append(sboxOptions,
		libnetwork.OptionHostsPath(hostsPath),
		libnetwork.OptionResolvConfPath(resolvConfPath),
	)

	return sboxOptions, nil
}

func (daemon *Daemon) initializeNetworkingPaths(ctr *container.Container, nc *container.Container) error {