- Currently it is being save upfront...
Signed-off-by: Alessandro Boch <aboch@docker.com>
| ... | ... |
@@ -265,7 +265,7 @@ func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork |
| 265 | 265 |
} |
| 266 | 266 |
|
| 267 | 267 |
// BuildCreateEndpointOptions builds endpoint options from a given network. |
| 268 |
-func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error) {
|
|
| 268 |
+func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *network.EndpointSettings) ([]libnetwork.EndpointOption, error) {
|
|
| 269 | 269 |
var ( |
| 270 | 270 |
portSpecs = make(nat.PortSet) |
| 271 | 271 |
bindings = make(nat.PortMap) |
| ... | ... |
@@ -278,7 +278,7 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([] |
| 278 | 278 |
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous()) |
| 279 | 279 |
} |
| 280 | 280 |
|
| 281 |
- if epConfig, ok := container.NetworkSettings.Networks[n.Name()]; ok {
|
|
| 281 |
+ if epConfig != nil {
|
|
| 282 | 282 |
ipam := epConfig.IPAMConfig |
| 283 | 283 |
if ipam != nil && (ipam.IPv4Address != "" || ipam.IPv6Address != "") {
|
| 284 | 284 |
createOptions = append(createOptions, |
| ... | ... |
@@ -775,11 +775,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName |
| 775 | 775 |
|
| 776 | 776 |
controller := daemon.netController |
| 777 | 777 |
|
| 778 |
- if endpointConfig != nil {
|
|
| 779 |
- container.NetworkSettings.Networks[n.Name()] = endpointConfig |
|
| 780 |
- } |
|
| 781 |
- |
|
| 782 |
- createOptions, err := container.BuildCreateEndpointOptions(n) |
|
| 778 |
+ createOptions, err := container.BuildCreateEndpointOptions(n, endpointConfig) |
|
| 783 | 779 |
if err != nil {
|
| 784 | 780 |
return err |
| 785 | 781 |
} |
| ... | ... |
@@ -797,6 +793,10 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName |
| 797 | 797 |
} |
| 798 | 798 |
}() |
| 799 | 799 |
|
| 800 |
+ if endpointConfig != nil {
|
|
| 801 |
+ container.NetworkSettings.Networks[n.Name()] = endpointConfig |
|
| 802 |
+ } |
|
| 803 |
+ |
|
| 800 | 804 |
if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil {
|
| 801 | 805 |
return err |
| 802 | 806 |
} |
| ... | ... |
@@ -1333,3 +1333,17 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *check.C) {
|
| 1333 | 1333 |
_, _, err = dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1.br.net1.google.com")
|
| 1334 | 1334 |
c.Assert(err, check.NotNil) |
| 1335 | 1335 |
} |
| 1336 |
+ |
|
| 1337 |
+func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) {
|
|
| 1338 |
+ dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top") |
|
| 1339 |
+ c.Assert(waitRun("bb"), check.IsNil)
|
|
| 1340 |
+ |
|
| 1341 |
+ ns0, _ := dockerCmd(c, "inspect", "--format='{{ .NetworkSettings.Networks.bridge }}'", "bb")
|
|
| 1342 |
+ |
|
| 1343 |
+ // A failing redundant network connect should not alter current container's endpoint settings |
|
| 1344 |
+ _, _, err := dockerCmdWithError("network", "connect", "bridge", "bb")
|
|
| 1345 |
+ c.Assert(err, check.NotNil) |
|
| 1346 |
+ |
|
| 1347 |
+ ns1, _ := dockerCmd(c, "inspect", "--format='{{ .NetworkSettings.Networks.bridge }}'", "bb")
|
|
| 1348 |
+ c.Assert(ns1, check.Equals, ns0) |
|
| 1349 |
+} |