@@ -380,6 +380,7 @@ func serviceDiscoveryOnDefaultNetwork() bool {
380380
381381func setupPathsAndSandboxOptions (container * container.Container , cfg * config.Config , sboxOptions * []libnetwork.SandboxOption ) error {
382382 var err error
383+ var originResolvConfPath string
383384
384385 // Set the correct paths for /etc/hosts and /etc/resolv.conf, based on the
385386 // networking-mode of the container. Note that containers with "container"
@@ -393,8 +394,8 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
393394 * sboxOptions = append (
394395 * sboxOptions ,
395396 libnetwork .OptionOriginHostsPath ("/etc/hosts" ),
396- libnetwork .OptionOriginResolvConfPath ("/etc/resolv.conf" ),
397397 )
398+ originResolvConfPath = "/etc/resolv.conf"
398399 case container .HostConfig .NetworkMode .IsUserDefined ():
399400 // The container uses a user-defined network. We use the embedded DNS
400401 // server for container name resolution and to act as a DNS forwarder
@@ -407,10 +408,7 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
407408 // If systemd-resolvd is used, the "upstream" DNS servers can be found in
408409 // /run/systemd/resolve/resolv.conf. We do not query those DNS servers
409410 // directly, as they can be dynamically reconfigured.
410- * sboxOptions = append (
411- * sboxOptions ,
412- libnetwork .OptionOriginResolvConfPath ("/etc/resolv.conf" ),
413- )
411+ originResolvConfPath = "/etc/resolv.conf"
414412 default :
415413 // For other situations, such as the default bridge network, container
416414 // discovery / name resolution is handled through /etc/hosts, and no
@@ -423,11 +421,15 @@ func setupPathsAndSandboxOptions(container *container.Container, cfg *config.Con
423421 // DNS servers on the host can be dynamically updated.
424422 //
425423 // Copy the host's resolv.conf for the container (/run/systemd/resolve/resolv.conf or /etc/resolv.conf)
426- * sboxOptions = append (
427- * sboxOptions ,
428- libnetwork .OptionOriginResolvConfPath (cfg .GetResolvConf ()),
429- )
424+ originResolvConfPath = cfg .GetResolvConf ()
425+ }
426+
427+ // Allow tests to point at their own resolv.conf file.
428+ if envPath := os .Getenv ("DOCKER_TEST_RESOLV_CONF_PATH" ); envPath != "" {
429+ log .G (context .TODO ()).Infof ("Using OriginResolvConfPath from env: %s" , envPath )
430+ originResolvConfPath = envPath
430431 }
432+ * sboxOptions = append (* sboxOptions , libnetwork .OptionOriginResolvConfPath (originResolvConfPath ))
431433
432434 container .HostsPath , err = container .GetRootResourcePath ("hosts" )
433435 if err != nil {
0 commit comments