Browse code

Use service alias and configure container's --net-alias

Signed-off-by: Madhu Venugopal <madhu@docker.com>

Madhu Venugopal authored on 2016/06/15 06:55:05
Showing 5 changed files
... ...
@@ -823,7 +823,7 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
823 823
 			})
824 824
 		}
825 825
 
826
-		createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, net.ParseIP(vip), portConfigs))
826
+		createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, net.ParseIP(vip), portConfigs, svcCfg.Aliases[n.ID()]))
827 827
 	}
828 828
 
829 829
 	if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
... ...
@@ -918,7 +918,7 @@ func populateNetworkID(ctx context.Context, c swarmapi.ControlClient, s *types.S
918 918
 		if err != nil {
919 919
 			return err
920 920
 		}
921
-		s.Networks[i] = types.NetworkAttachmentConfig{Target: apiNetwork.ID}
921
+		s.Networks[i].Target = apiNetwork.ID
922 922
 	}
923 923
 	return nil
924 924
 }
... ...
@@ -126,7 +126,6 @@ func (c *containerAdapter) create(ctx context.Context, backend executorpkg.Backe
126 126
 
127 127
 	if nc != nil {
128 128
 		for n, ep := range nc.EndpointsConfig {
129
-			logrus.Errorf("CONNECT %s : %v", n, ep.IPAMConfig.IPv4Address)
130 129
 			if err := backend.ConnectContainerToNetwork(cr.ID, n, ep); err != nil {
131 130
 				return err
132 131
 			}
... ...
@@ -348,6 +348,7 @@ func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig {
348 348
 	log.Printf("Creating service config in agent for t = %+v", c.task)
349 349
 	svcCfg := &clustertypes.ServiceConfig{
350 350
 		Name:             c.task.ServiceAnnotations.Name,
351
+		Aliases:          make(map[string][]string),
351 352
 		ID:               c.task.ServiceID,
352 353
 		VirtualAddresses: make(map[string]*clustertypes.VirtualAddress),
353 354
 	}
... ...
@@ -357,6 +358,9 @@ func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig {
357 357
 			// We support only IPv4 virtual IP for now.
358 358
 			IPv4: c.virtualIP(na.Network.ID),
359 359
 		}
360
+		if len(na.Aliases) > 0 {
361
+			svcCfg.Aliases[na.Network.ID] = na.Aliases
362
+		}
360 363
 	}
361 364
 
362 365
 	if c.task.Endpoint != nil {
... ...
@@ -31,6 +31,7 @@ type PortConfig struct {
31 31
 type ServiceConfig struct {
32 32
 	ID               string
33 33
 	Name             string
34
+	Aliases          map[string][]string
34 35
 	VirtualAddresses map[string]*VirtualAddress
35 36
 	ExposedPorts     []*PortConfig
36 37
 }