Fix regression on --link on bridge network

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2016-07-22 15:42:26 -07:00
parent 2b3148c720
commit 3a3f800ff4
2 changed files with 32 additions and 6 deletions

View file

@ -177,11 +177,12 @@ func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]lib
// 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
// 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
}
if container.NetworkSettings.Networks[defaultNetName].EndpointID == "" {
if bridgeSettings.EndpointID == "" {
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) {
if daemon.configStore.DisableBridge || !container.HostConfig.NetworkMode.IsPrivate() {
continue

View file

@ -31,10 +31,33 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) {
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top")
dockerCmd(c, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top")
// Test with the three different ways of specifying the default network on Linux
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"
// 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
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) {