mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Enable embedded DNS server on network connect to a user defined network
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
parent
3e6a42bcdb
commit
5f22db217a
1 changed files with 14 additions and 40 deletions
|
@ -322,11 +322,15 @@ func (sb *sandbox) startResolver() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sb.rebuildDNS()
|
err = sb.rebuildDNS()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Updating resolv.conf failed for container %s, %q", sb.ContainerID(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
sb.resolver.SetExtServers(sb.extDNS)
|
sb.resolver.SetExtServers(sb.extDNS)
|
||||||
|
|
||||||
sb.osSbox.InvokeFunc(sb.resolver.SetupFunc())
|
sb.osSbox.InvokeFunc(sb.resolver.SetupFunc())
|
||||||
if err := sb.resolver.Start(); err != nil {
|
if err = sb.resolver.Start(); err != nil {
|
||||||
log.Errorf("Resolver Setup/Start failed for container %s, %q", sb.ContainerID(), err)
|
log.Errorf("Resolver Setup/Start failed for container %s, %q", sb.ContainerID(), err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -897,36 +901,21 @@ func (sb *sandbox) updateDNS(ipv6Enabled bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = ioutil.WriteFile(sb.config.resolvConfPath, newRC.Content, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// for atomic updates to these files, use temporary files with os.Rename:
|
// write the new hash in a temp file and rename it to make the update atomic
|
||||||
dir := path.Dir(sb.config.resolvConfPath)
|
dir := path.Dir(sb.config.resolvConfPath)
|
||||||
tmpHashFile, err := ioutil.TempFile(dir, "hash")
|
tmpHashFile, err := ioutil.TempFile(dir, "hash")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tmpResolvFile, err := ioutil.TempFile(dir, "resolv")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change the perms to filePerm (0644) since ioutil.TempFile creates it by default as 0600
|
|
||||||
if err := os.Chmod(tmpResolvFile.Name(), filePerm); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the updates to the temp files
|
|
||||||
if err = ioutil.WriteFile(tmpHashFile.Name(), []byte(newRC.Hash), filePerm); err != nil {
|
if err = ioutil.WriteFile(tmpHashFile.Name(), []byte(newRC.Hash), filePerm); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = ioutil.WriteFile(tmpResolvFile.Name(), newRC.Content, filePerm); err != nil {
|
return os.Rename(tmpHashFile.Name(), hashFile)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// rename the temp files for atomic replace
|
|
||||||
if err = os.Rename(tmpHashFile.Name(), hashFile); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.Rename(tmpResolvFile.Name(), sb.config.resolvConfPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embedded DNS server has to be enabled for this sandbox. Rebuild the container's
|
// Embedded DNS server has to be enabled for this sandbox. Rebuild the container's
|
||||||
|
@ -952,23 +941,8 @@ func (sb *sandbox) rebuildDNS() error {
|
||||||
// Resolver returns the options in the format resolv.conf expects
|
// Resolver returns the options in the format resolv.conf expects
|
||||||
dnsOptionsList = append(dnsOptionsList, sb.resolver.ResolverOptions()...)
|
dnsOptionsList = append(dnsOptionsList, sb.resolver.ResolverOptions()...)
|
||||||
|
|
||||||
dir := path.Dir(sb.config.resolvConfPath)
|
_, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList)
|
||||||
tmpResolvFile, err := ioutil.TempFile(dir, "resolv")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
// Change the perms to filePerm (0644) since ioutil.TempFile creates it by default as 0600
|
|
||||||
if err := os.Chmod(tmpResolvFile.Name(), filePerm); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = resolvconf.Build(tmpResolvFile.Name(), dnsList, dnsSearchList, dnsOptionsList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.Rename(tmpResolvFile.Name(), sb.config.resolvConfPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// joinLeaveStart waits to ensure there are no joins or leaves in progress and
|
// joinLeaveStart waits to ensure there are no joins or leaves in progress and
|
||||||
|
|
Loading…
Add table
Reference in a new issue