|
@@ -8,12 +8,19 @@ import (
|
|
"regexp"
|
|
"regexp"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
+ "github.com/docker/docker/daemon/config"
|
|
|
|
+ "github.com/docker/docker/internal/procfs"
|
|
"github.com/docker/docker/pkg/fileutils"
|
|
"github.com/docker/docker/pkg/fileutils"
|
|
"github.com/docker/docker/pkg/mount"
|
|
"github.com/docker/docker/pkg/mount"
|
|
"github.com/pkg/errors"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const (
|
|
|
|
+ defaultResolvConf = "/etc/resolv.conf"
|
|
|
|
+ alternateResolvConf = "/run/systemd/resolve/resolv.conf"
|
|
|
|
+)
|
|
|
|
+
|
|
// On Linux, plugins use a static path for storing execution state,
|
|
// On Linux, plugins use a static path for storing execution state,
|
|
// instead of deriving path from daemon's exec-root. This is because
|
|
// instead of deriving path from daemon's exec-root. This is because
|
|
// plugin socket files are created here and they cannot exceed max
|
|
// plugin socket files are created here and they cannot exceed max
|
|
@@ -131,3 +138,30 @@ func shouldUnmountRoot(root string, info *mount.Info) bool {
|
|
}
|
|
}
|
|
return hasMountinfoOption(info.Optional, sharedPropagationOption)
|
|
return hasMountinfoOption(info.Optional, sharedPropagationOption)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// setupResolvConf sets the appropriate resolv.conf file if not specified
|
|
|
|
+// When systemd-resolved is running the default /etc/resolv.conf points to
|
|
|
|
+// localhost. In this case fetch the alternative config file that is in a
|
|
|
|
+// different path so that containers can use it
|
|
|
|
+// In all the other cases fallback to the default one
|
|
|
|
+func setupResolvConf(config *config.Config) {
|
|
|
|
+ if config.ResolvConf != "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ config.ResolvConf = defaultResolvConf
|
|
|
|
+ pids, err := procfs.PidOf("systemd-resolved")
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Errorf("unable to check systemd-resolved status: %s", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if len(pids) > 0 && pids[0] > 0 {
|
|
|
|
+ _, err := os.Stat(alternateResolvConf)
|
|
|
|
+ if err == nil {
|
|
|
|
+ logrus.Infof("systemd-resolved is running, so using resolvconf: %s", alternateResolvConf)
|
|
|
|
+ config.ResolvConf = alternateResolvConf
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ logrus.Infof("systemd-resolved is running, but %s is not present, fallback to %s", alternateResolvConf, defaultResolvConf)
|
|
|
|
+ }
|
|
|
|
+}
|