-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update /etc/hosts when linked container is restarted #7677
Update /etc/hosts when linked container is restarted #7677
Conversation
@@ -297,6 +297,9 @@ func (container *Container) Start() (err error) { | |||
if err := container.initializeNetworking(); err != nil { | |||
return err | |||
} | |||
if err := container.updateParentsHosts(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to remove records from hosts on container stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think that’s necessary; the next time the container starts the file will be rewritten anyhow.
-Erik
On Aug 22, 2014, at 1:48 AM, Alexandr Morozov notifications@github.com wrote:
In daemon/container.go:
@@ -297,6 +297,9 @@ func (container *Container) Start() (err error) {
if err := container.initializeNetworking(); err != nil {
return err
}
- if err := container.updateParentsHosts(); err != nil {
I wonder if we need to remove records from hosts on container stop.—
Reply to this email directly or view it on GitHub https://github.com/docker/docker/pull/7677/files#r16587815.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @erikh
TestHostsLinkedContainerUpdate fails every time for me. |
} | ||
defer os.RemoveAll(tmpdir) | ||
|
||
_, err = runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sleep", "5")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use runCommandWithOutput
and print output in Fatal
. Because now test failing for me and I have no idea why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
return err | ||
} | ||
for _, cid := range parents { | ||
if cid != "0" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is some super deep nesting.
Could we change these ifs to be the other way
if cid == "0" {
return nil
}
etc, on down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You meant continue
instead or return nil
I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for if cid == "0" { continue }
[Communication between containers](#between-containers). If the linked | ||
container is restarted, it is likely to get a different IP address; to | ||
cater for this, Docker then updates the child container's `/etc/hosts` file | ||
`ALIAS` entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd reword [this] to something like this:
Communication between containers.
On restart, Docker may assign a different IP address to the linked containers.
To keep the link, Docker then updates theALIAS
entry in the recipient
(i.e., child) container's/etc/hosts
file.
Or:
Communication between containers.
Docker updates theALIAS
entry in the/etc/hosts
file of the recipient
containers (i.e., children) in order to keep the link since Docker may
assign a different IP address to the linked containers on restart.
Please note that "to keep the link", however, might not be the correct term to use here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the second one better, I'll be using that.
@LK4D4, can you verify the errors are still happening? Otherwise, I believe I have addressed all issues docs and otherwise. |
I'll try in a few minutes. |
@erikh all working OK now. Thank you. |
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 parent: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message could be more descriptive: Failed to update /etc/hosts of parent container
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now. Thanks!
-Erik
On Aug 25, 2014, at 11:32 AM, Tibor Vass notifications@github.com wrote:
In daemon/container.go:
@@ -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 {
Error message could be more descriptive: Failed to update /etc/hosts of parent container.return fmt.Errorf("Failed to update parent: %v", err)
—
Reply to this email directly or view it on GitHub.
@erikh Your DCO has vieux's name and email :) |
It's also committed by @vieux :) It's his patch, I tried to preserve it. |
@erikh Sorry, I meant that, there are 2 DCOs (1 for vieux and 1 for you), and the 2nd one (yours) has still vieux's name and email. |
Should be fixed now @tiborvass. Thanks. |
LGTM |
[Communication between containers](#between-containers). | ||
[Communication between containers](#between-containers). Docker updates | ||
the ALIAS entry in the /etc/hosts file of the recipient containers (i.e., | ||
children) in order to keep the link since Docker may assign a different IP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we want to remove references to parent/child in docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Functionally looks good. Just need another commit with some unit tests for the Update and Parents functions in graphd and the network code |
Updated, PTAL. On Aug 25, 2014, at 4:23 PM, Michael Crosby notifications@github.com wrote:
|
[Communication between containers](#between-containers). Docker updates | ||
the ALIAS entry in the /etc/hosts file of the recipient containers | ||
in order to keep the link since Docker may assign a different IP | ||
address to the linked containers on restart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should flip this sentence so the context is at the beginning where it can be more helpful. So,
Because Docker may assign a different IP address to the linked containers on restart, Docker updates the ALIAS entry in the /etc/hosts
file of the recipient containers.
Docs LGTM once my minor comment is addressed. |
@fredlf, @crosbymichael, PTAL On Aug 26, 2014, at 10:06 AM, Fred Lifton notifications@github.com wrote:
|
@erikh needs rebased |
Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
@erikh, @crosbymichael said it needs rebased |
👿 |
rebased
|
LGTM |
@crosbymichael please merge |
LGTM |
Update /etc/hosts when linked container is restarted
In our next release, 1.3 On Fri, Aug 29, 2014 at 12:44 AM, omeid notifications@github.com wrote:
Victor VIEUX |
Carry of #7092
closes #7092
fixes #6350
/cc @vieux