mirror of https://github.com/docker/compose.git
Set networking_config when creating a container.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
abb5ae7fe4
commit
e1356e1f6f
|
@ -461,10 +461,9 @@ class Service(object):
|
|||
container.id,
|
||||
network)
|
||||
|
||||
aliases = netdefs.get('aliases', [])
|
||||
self.client.connect_container_to_network(
|
||||
container.id, network,
|
||||
aliases=list(self._get_aliases(container).union(aliases)),
|
||||
aliases=self._get_aliases(netdefs, container),
|
||||
ipv4_address=netdefs.get('ipv4_address', None),
|
||||
ipv6_address=netdefs.get('ipv6_address', None),
|
||||
links=self._get_links(False))
|
||||
|
@ -534,11 +533,32 @@ class Service(object):
|
|||
numbers = [c.number for c in containers]
|
||||
return 1 if not numbers else max(numbers) + 1
|
||||
|
||||
def _get_aliases(self, container):
|
||||
if container.labels.get(LABEL_ONE_OFF) == "True":
|
||||
def _get_aliases(self, network, container=None):
|
||||
if container and container.labels.get(LABEL_ONE_OFF) == "True":
|
||||
return set()
|
||||
|
||||
return {self.name, container.short_id}
|
||||
return list(
|
||||
{self.name} |
|
||||
({container.short_id} if container else set()) |
|
||||
set(network.get('aliases', ()))
|
||||
)
|
||||
|
||||
def build_default_networking_config(self):
|
||||
if not self.networks:
|
||||
return {}
|
||||
|
||||
network = self.networks[self.network_mode.id]
|
||||
endpoint = {
|
||||
'Aliases': self._get_aliases(network),
|
||||
'IPAMConfig': {},
|
||||
}
|
||||
|
||||
if network.get('ipv4_address'):
|
||||
endpoint['IPAMConfig']['IPv4Address'] = network.get('ipv4_address')
|
||||
if network.get('ipv6_address'):
|
||||
endpoint['IPAMConfig']['IPv6Address'] = network.get('ipv6_address')
|
||||
|
||||
return {"EndpointsConfig": {self.network_mode.id: endpoint}}
|
||||
|
||||
def _get_links(self, link_to_self):
|
||||
links = {}
|
||||
|
@ -634,6 +654,10 @@ class Service(object):
|
|||
override_options,
|
||||
one_off=one_off)
|
||||
|
||||
networking_config = self.build_default_networking_config()
|
||||
if networking_config:
|
||||
container_options['networking_config'] = networking_config
|
||||
|
||||
container_options['environment'] = format_environment(
|
||||
container_options['environment'])
|
||||
return container_options
|
||||
|
|
Loading…
Reference in New Issue