mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon.setupPathsAndSandboxOptions() skip resolving symlinks
This came up in a review of a5324d6950
, but
for some reason that comment didn't find its way to GitHub, and/or I
forgot to push the change.
These files are "copied" by reading their content with ioutil.Readfile(),
resolving the symlinks should therefore not be needed, and paths can be
passed as-is;
```go
func copyFile(src, dst string) error {
sBytes, err := ioutil.ReadFile(src)
if err != nil {
return err
}
return ioutil.WriteFile(dst, sBytes, filePerm)
}
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
52d019221b
commit
cf169b45bb
1 changed files with 11 additions and 23 deletions
|
@ -399,21 +399,11 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
|
|||
case container.HostConfig.NetworkMode.IsHost():
|
||||
// In host-mode networking, the container does not have its own networking
|
||||
// namespace, so both `/etc/hosts` and `/etc/resolv.conf` should be the same
|
||||
// as on the host itself. The container gets a copy of these files, but they
|
||||
// may be symlinked, so resolve the original path first.
|
||||
etcHosts, err := filepath.EvalSymlinks("/etc/hosts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resolvConf, err := filepath.EvalSymlinks("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// as on the host itself. The container gets a copy of these files.
|
||||
*sboxOptions = append(
|
||||
*sboxOptions,
|
||||
libnetwork.OptionOriginHostsPath(etcHosts),
|
||||
libnetwork.OptionOriginResolvConfPath(resolvConf),
|
||||
libnetwork.OptionOriginHostsPath("/etc/hosts"),
|
||||
libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
|
||||
)
|
||||
case container.HostConfig.NetworkMode.IsUserDefined():
|
||||
// The container uses a user-defined network. We use the embedded DNS
|
||||
|
@ -427,11 +417,10 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
|
|||
// 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.
|
||||
resolvConf, err := filepath.EvalSymlinks("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*sboxOptions = append(*sboxOptions, libnetwork.OptionOriginResolvConfPath(resolvConf))
|
||||
*sboxOptions = append(
|
||||
*sboxOptions,
|
||||
libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
|
||||
)
|
||||
default:
|
||||
// For other situations, such as the default bridge network, container
|
||||
// discovery / name resolution is handled through /etc/hosts, and no
|
||||
|
@ -444,11 +433,10 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
|
|||
// 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)
|
||||
resolvConf, err := filepath.EvalSymlinks(daemon.configStore.GetResolvConf())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*sboxOptions = append(*sboxOptions, libnetwork.OptionOriginResolvConfPath(resolvConf))
|
||||
*sboxOptions = append(
|
||||
*sboxOptions,
|
||||
libnetwork.OptionOriginResolvConfPath(daemon.configStore.GetResolvConf()),
|
||||
)
|
||||
}
|
||||
|
||||
container.HostsPath, err = container.GetRootResourcePath("hosts")
|
||||
|
|
Loading…
Reference in a new issue