|
@@ -380,6 +380,7 @@ func serviceDiscoveryOnDefaultNetwork() bool {
|
|
|
|
|
|
func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Config, sboxOptions *[]libnetwork.SandboxOption) error {
|
|
|
var err error
|
|
|
+ var originResolvConfPath string
|
|
|
|
|
|
// Set the correct paths for /etc/hosts and /etc/resolv.conf, based on the
|
|
|
// networking-mode of the container. Note that containers with "container"
|
|
@@ -393,8 +394,8 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
|
|
|
*sboxOptions = append(
|
|
|
*sboxOptions,
|
|
|
libnetwork.OptionOriginHostsPath("/etc/hosts"),
|
|
|
- libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
|
|
|
)
|
|
|
+ originResolvConfPath = "/etc/resolv.conf"
|
|
|
case container.HostConfig.NetworkMode.IsUserDefined():
|
|
|
// The container uses a user-defined network. We use the embedded DNS
|
|
|
// server for container name resolution and to act as a DNS forwarder
|
|
@@ -407,10 +408,7 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
|
|
|
// 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.
|
|
|
- *sboxOptions = append(
|
|
|
- *sboxOptions,
|
|
|
- libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
|
|
|
- )
|
|
|
+ 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
|
|
@@ -423,11 +421,15 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
|
|
|
// 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)
|
|
|
- *sboxOptions = append(
|
|
|
- *sboxOptions,
|
|
|
- libnetwork.OptionOriginResolvConfPath(cfg.GetResolvConf()),
|
|
|
- )
|
|
|
+ originResolvConfPath = cfg.GetResolvConf()
|
|
|
+ }
|
|
|
+
|
|
|
+ // Allow tests to point at their own resolv.conf file.
|
|
|
+ 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))
|
|
|
|
|
|
container.HostsPath, err = container.GetRootResourcePath("hosts")
|
|
|
if err != nil {
|