mirror of https://github.com/docker/docs.git
Fix regression on --link on bridge network
Signed-off-by: Alessandro Boch <aboch@docker.com> (cherry picked from commit 3a3f800ff48ddfa729f1db7898bf689d25a6d4cf) Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
1bb38f1a2b
commit
9e006577f4
|
@ -177,11 +177,12 @@ func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]lib
|
||||||
// Legacy Link feature is supported only for the default bridge network.
|
// Legacy Link feature is supported only for the default bridge network.
|
||||||
// return if this call to build join options is not for default bridge network
|
// return if this call to build join options is not for default bridge network
|
||||||
// Legacy Link is only supported by docker run --link
|
// Legacy Link is only supported by docker run --link
|
||||||
if _, ok := container.NetworkSettings.Networks[defaultNetName]; !container.HostConfig.NetworkMode.IsDefault() || !ok {
|
bridgeSettings, ok := container.NetworkSettings.Networks[defaultNetName]
|
||||||
|
if !ok {
|
||||||
return sboxOptions, nil
|
return sboxOptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if container.NetworkSettings.Networks[defaultNetName].EndpointID == "" {
|
if bridgeSettings.EndpointID == "" {
|
||||||
return sboxOptions, nil
|
return sboxOptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +210,6 @@ func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]lib
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bridgeSettings := container.NetworkSettings.Networks[defaultNetName]
|
|
||||||
for alias, parent := range daemon.parents(container) {
|
for alias, parent := range daemon.parents(container) {
|
||||||
if daemon.configStore.DisableBridge || !container.HostConfig.NetworkMode.IsPrivate() {
|
if daemon.configStore.DisableBridge || !container.HostConfig.NetworkMode.IsPrivate() {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -31,10 +31,33 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
dockerCmd(c, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top")
|
// Test with the three different ways of specifying the default network on Linux
|
||||||
dockerCmd(c, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top")
|
testLinkPingOnNetwork(c, "")
|
||||||
|
testLinkPingOnNetwork(c, "default")
|
||||||
|
testLinkPingOnNetwork(c, "bridge")
|
||||||
|
}
|
||||||
|
|
||||||
runArgs := []string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sh", "-c"}
|
func testLinkPingOnNetwork(c *check.C, network string) {
|
||||||
|
var postArgs []string
|
||||||
|
if network != "" {
|
||||||
|
postArgs = append(postArgs, []string{"--net", network}...)
|
||||||
|
}
|
||||||
|
postArgs = append(postArgs, []string{"busybox", "top"}...)
|
||||||
|
runArgs1 := append([]string{"run", "-d", "--name", "container1", "--hostname", "fred"}, postArgs...)
|
||||||
|
runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...)
|
||||||
|
|
||||||
|
// Run the two named containers
|
||||||
|
dockerCmd(c, runArgs1...)
|
||||||
|
dockerCmd(c, runArgs2...)
|
||||||
|
|
||||||
|
postArgs = []string{}
|
||||||
|
if network != "" {
|
||||||
|
postArgs = append(postArgs, []string{"--net", network}...)
|
||||||
|
}
|
||||||
|
postArgs = append(postArgs, []string{"busybox", "sh", "-c"}...)
|
||||||
|
|
||||||
|
// Format a run for a container which links to the other two
|
||||||
|
runArgs := append([]string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2"}, postArgs...)
|
||||||
pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1"
|
pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1"
|
||||||
|
|
||||||
// test ping by alias, ping by name, and ping by hostname
|
// test ping by alias, ping by name, and ping by hostname
|
||||||
|
@ -45,6 +68,9 @@ func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
||||||
// 3. Ping by hostname
|
// 3. Ping by hostname
|
||||||
dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
|
dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
|
||||||
|
|
||||||
|
// Clean for next round
|
||||||
|
dockerCmd(c, "rm", "-f", "container1")
|
||||||
|
dockerCmd(c, "rm", "-f", "container2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
||||||
|
|
Loading…
Reference in New Issue