浏览代码

Docker changes for libnetwork vendoring..

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
Santhosh Manohar 9 年之前
父节点
当前提交
64a6dc3558

+ 1 - 1
api/server/router/network/network_routes.go

@@ -182,7 +182,7 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
 }
 }
 
 
 func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
 func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
-	id, ipv4conf, ipv6conf := nw.Info().IpamConfig()
+	id, _, ipv4conf, ipv6conf := nw.Info().IpamConfig()
 
 
 	r.IPAM.Driver = id
 	r.IPAM.Driver = id
 
 

+ 4 - 0
container/container_unix.go

@@ -269,6 +269,10 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([]
 		}
 		}
 	}
 	}
 
 
+	if !container.HostConfig.NetworkMode.IsUserDefined() {
+		createOptions = append(createOptions, libnetwork.CreateOptionDisableResolution())
+	}
+
 	// Other configs are applicable only for the endpoint in the network
 	// Other configs are applicable only for the endpoint in the network
 	// to which container was connected to on docker run.
 	// to which container was connected to on docker run.
 	if n.Name() != container.HostConfig.NetworkMode.NetworkName() &&
 	if n.Name() != container.HostConfig.NetworkMode.NetworkName() &&

+ 1 - 1
daemon/container_operations_unix.go

@@ -665,7 +665,7 @@ func validateNetworkingConfig(n libnetwork.Network, epConfig *networktypes.Endpo
 	if !hasUserDefinedIPAddress(epConfig) {
 	if !hasUserDefinedIPAddress(epConfig) {
 		return nil
 		return nil
 	}
 	}
-	_, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig()
+	_, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig()
 	for _, s := range []struct {
 	for _, s := range []struct {
 		ipConfigured  bool
 		ipConfigured  bool
 		subnetConfigs []*libnetwork.IpamConf
 		subnetConfigs []*libnetwork.IpamConf

+ 1 - 1
daemon/daemon_unix.go

@@ -607,7 +607,7 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
 			netlabel.GenericData: netOption,
 			netlabel.GenericData: netOption,
 			netlabel.EnableIPv6:  config.Bridge.EnableIPv6,
 			netlabel.EnableIPv6:  config.Bridge.EnableIPv6,
 		}),
 		}),
-		libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf),
+		libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
 		libnetwork.NetworkOptionDeferIPv6Alloc(deferIPv6Alloc))
 		libnetwork.NetworkOptionDeferIPv6Alloc(deferIPv6Alloc))
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
 		return fmt.Errorf("Error creating default \"bridge\" network: %v", err)

+ 1 - 1
daemon/network.go

@@ -114,7 +114,7 @@ func (daemon *Daemon) CreateNetwork(name, driver string, ipam network.IPAM, opti
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf))
+	nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, nil))
 	nwOptions = append(nwOptions, libnetwork.NetworkOptionDriverOpts(options))
 	nwOptions = append(nwOptions, libnetwork.NetworkOptionDriverOpts(options))
 	n, err := c.NewNetwork(driver, name, nwOptions...)
 	n, err := c.NewNetwork(driver, name, nwOptions...)
 	if err != nil {
 	if err != nil {

+ 1 - 17
docs/userguide/networking/work-with-networks.md

@@ -252,24 +252,8 @@ lo        Link encap:Local Loopback
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           collisions:0 txqueuelen:0
           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
-```
-
-Display the container's `etc/hosts` file:
-
-```bash
-/ # cat /etc/hosts
-172.17.0.3	498eaaaf328e
-127.0.0.1	localhost
-::1	localhost ip6-localhost ip6-loopback
-fe00::0	ip6-localnet
-ff00::0	ip6-mcastprefix
-ff02::1	ip6-allnodes
-ff02::2	ip6-allrouters
-172.21.3.3	container3
-172.21.3.3	container3.isolated_nw
-```
 
 
-On the `isolated_nw` which was user defined, the Docker network feature updated the `/etc/hosts` with the proper name resolution.  Inside of `container2` it is possible to ping `container3` by name.
+On the `isolated_nw` which was user defined, the Docker embedded DNS server enables name resolution for other containers in the network.  Inside of `container2` it is possible to ping `container3` by name.
 
 
 ```bash
 ```bash
 / # ping -w 4 container3
 / # ping -w 4 container3

+ 13 - 35
integration-cli/docker_cli_network_unix_test.go

@@ -622,27 +622,6 @@ func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(string(hosts), checker.Equals, string(hostsPost),
 	c.Assert(string(hosts), checker.Equals, string(hostsPost),
 		check.Commentf("Unexpected %s change on second network connection", hostsFile))
 		check.Commentf("Unexpected %s change on second network connection", hostsFile))
-
-	cName := "container3"
-	out, err = s.d.Cmd("run", "-d", "--net", network, "--name", cName, "busybox", "top")
-	c.Assert(err, check.IsNil, check.Commentf(out))
-	cid3 := strings.TrimSpace(out)
-	defer s.d.Cmd("stop", cid3)
-
-	// container1 etc/hosts file should contain an entry for the third container
-	hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile)
-	c.Assert(err, checker.IsNil)
-	c.Assert(string(hostsPost), checker.Contains, cName,
-		check.Commentf("Container 1  %s file does not contain entries for named container %q: %s", hostsFile, cName, string(hostsPost)))
-
-	// on container3 disconnect, first container's etc/hosts should go back to original form
-	out, err = s.d.Cmd("network", "disconnect", network, cid3)
-	c.Assert(err, check.IsNil, check.Commentf(out))
-
-	hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile)
-	c.Assert(err, checker.IsNil)
-	c.Assert(string(hosts), checker.Equals, string(hostsPost),
-		check.Commentf("Unexpected %s content after disconnecting from second network", hostsFile))
 }
 }
 
 
 func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
 func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
@@ -693,28 +672,27 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
 	out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "--name", cName, "busybox", "top")
 	out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "--name", cName, "busybox", "top")
 	cid3 := strings.TrimSpace(out)
 	cid3 := strings.TrimSpace(out)
 
 
-	// verify etc/hosts file for first two containers contains the named container entry
-	hosts1post, err = readContainerFileWithExec(cid1, hostsFile)
-	c.Assert(err, checker.IsNil)
-	c.Assert(string(hosts1post), checker.Contains, cName,
-		check.Commentf("Container 1  %s file does not contain entries for named container %q: %s", hostsFile, cName, string(hosts1post)))
-
-	hosts2post, err := readContainerFileWithExec(cid2, hostsFile)
-	c.Assert(err, checker.IsNil)
-	c.Assert(string(hosts2post), checker.Contains, cName,
-		check.Commentf("Container 2  %s file does not contain entries for named container %q: %s", hostsFile, cName, string(hosts2post)))
+	// verify that container 1 and 2 can ping the named container
+	dockerCmd(c, "exec", cid1, "ping", "-c", "1", cName)
+	dockerCmd(c, "exec", cid2, "ping", "-c", "1", cName)
 
 
-	// Stop named container and verify first two containers' etc/hosts entries are back to original
+	// Stop named container and verify first two containers' etc/hosts file hasn't changed
 	dockerCmd(c, "stop", cid3)
 	dockerCmd(c, "stop", cid3)
 	hosts1post, err = readContainerFileWithExec(cid1, hostsFile)
 	hosts1post, err = readContainerFileWithExec(cid1, hostsFile)
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(string(hosts1), checker.Equals, string(hosts1post),
 	c.Assert(string(hosts1), checker.Equals, string(hosts1post),
-		check.Commentf("Unexpected %s change on anonymous container creation", hostsFile))
+		check.Commentf("Unexpected %s change on name container creation", hostsFile))
 
 
-	hosts2post, err = readContainerFileWithExec(cid2, hostsFile)
+	hosts2post, err := readContainerFileWithExec(cid2, hostsFile)
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(string(hosts2), checker.Equals, string(hosts2post),
 	c.Assert(string(hosts2), checker.Equals, string(hosts2post),
-		check.Commentf("Unexpected %s change on anonymous container creation", hostsFile))
+		check.Commentf("Unexpected %s change on name container creation", hostsFile))
+
+	// verify that container 1 and 2 can't ping the named container now
+	_, _, err = dockerCmdWithError("exec", cid1, "ping", "-c", "1", cName)
+	c.Assert(err, check.NotNil)
+	_, _, err = dockerCmdWithError("exec", cid2, "ping", "-c", "1", cName)
+	c.Assert(err, check.NotNil)
 }
 }
 
 
 func (s *DockerNetworkSuite) TestDockerNetworkLinkOndefaultNetworkOnly(c *check.C) {
 func (s *DockerNetworkSuite) TestDockerNetworkLinkOndefaultNetworkOnly(c *check.C) {