mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-03 23:38:24 +00:00
Merge pull request #7677 from erikh/update_hosts_linked_containers
Update /etc/hosts when linked container is restarted
This commit is contained in:
+32
-4
@@ -297,6 +297,9 @@ func (container *Container) Start() (err error) {
|
||||
if err := container.initializeNetworking(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.updateParentsHosts(); err != nil {
|
||||
return err
|
||||
}
|
||||
container.verifyDaemonSettings()
|
||||
if err := prepareVolumesForContainer(container); err != nil {
|
||||
return err
|
||||
@@ -390,10 +393,7 @@ func (container *Container) buildHostnameFile() error {
|
||||
return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
|
||||
}
|
||||
|
||||
func (container *Container) buildHostnameAndHostsFiles(IP string) error {
|
||||
if err := container.buildHostnameFile(); err != nil {
|
||||
return err
|
||||
}
|
||||
func (container *Container) buildHostsFiles(IP string) error {
|
||||
|
||||
hostsPath, err := container.getRootResourcePath("hosts")
|
||||
if err != nil {
|
||||
@@ -416,6 +416,14 @@ func (container *Container) buildHostnameAndHostsFiles(IP string) error {
|
||||
return etchosts.Build(container.HostsPath, IP, container.Config.Hostname, container.Config.Domainname, &extraContent)
|
||||
}
|
||||
|
||||
func (container *Container) buildHostnameAndHostsFiles(IP string) error {
|
||||
if err := container.buildHostnameFile(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return container.buildHostsFiles(IP)
|
||||
}
|
||||
|
||||
func (container *Container) allocateNetwork() error {
|
||||
mode := container.hostConfig.NetworkMode
|
||||
if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() {
|
||||
@@ -878,6 +886,26 @@ func (container *Container) setupContainerDns() error {
|
||||
return ioutil.WriteFile(container.ResolvConfPath, resolvConf, 0644)
|
||||
}
|
||||
|
||||
func (container *Container) updateParentsHosts() error {
|
||||
parents, err := container.daemon.Parents(container.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, cid := range parents {
|
||||
if cid == "0" {
|
||||
continue
|
||||
}
|
||||
|
||||
c := container.daemon.Get(cid)
|
||||
if c != nil && !container.daemon.config.DisableNetwork && !container.hostConfig.NetworkMode.IsContainer() && !container.hostConfig.NetworkMode.IsHost() {
|
||||
if err := etchosts.Update(c.HostsPath, container.NetworkSettings.IPAddress, container.Name[1:]); err != nil {
|
||||
return fmt.Errorf("Failed to update /etc/hosts in parent container: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) initializeNetworking() error {
|
||||
var err error
|
||||
if container.hostConfig.NetworkMode.IsHost() {
|
||||
|
||||
@@ -621,6 +621,15 @@ func (daemon *Daemon) Children(name string) (map[string]*Container, error) {
|
||||
return children, nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) Parents(name string) ([]string, error) {
|
||||
name, err := GetFullContainerName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return daemon.containerGraph.Parents(name)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) RegisterLink(parent, child *Container, alias string) error {
|
||||
fullName := path.Join(parent.Name, alias)
|
||||
if !daemon.containerGraph.Exists(fullName) {
|
||||
|
||||
Reference in New Issue
Block a user