mirror of https://github.com/docker/compose.git
Containers join each network aliased to their service's name
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
2a2eb81215
commit
abd031cb3d
|
@ -18,7 +18,5 @@ COMPOSEFILE_VERSIONS = (1, 2)
|
|||
|
||||
API_VERSIONS = {
|
||||
1: '1.21',
|
||||
|
||||
# TODO: update to 1.22 when there's a Docker 1.10 build to test against
|
||||
2: '1.21',
|
||||
2: '1.22',
|
||||
}
|
||||
|
|
|
@ -427,7 +427,9 @@ class Service(object):
|
|||
def connect_container_to_networks(self, container):
|
||||
for network in self.networks:
|
||||
log.debug('Connecting "{}" to "{}"'.format(container.name, network))
|
||||
self.client.connect_container_to_network(container.id, network)
|
||||
self.client.connect_container_to_network(
|
||||
container.id, network,
|
||||
aliases=[self.name])
|
||||
|
||||
def remove_duplicate_containers(self, timeout=DEFAULT_TIMEOUT):
|
||||
for c in self.duplicate_containers():
|
||||
|
@ -597,6 +599,8 @@ class Service(object):
|
|||
override_options,
|
||||
one_off=one_off)
|
||||
|
||||
container_options['networking_config'] = self._get_container_networking_config()
|
||||
|
||||
return container_options
|
||||
|
||||
def _get_container_host_config(self, override_options, one_off=False):
|
||||
|
@ -631,6 +635,12 @@ class Service(object):
|
|||
cpu_quota=options.get('cpu_quota'),
|
||||
)
|
||||
|
||||
def _get_container_networking_config(self):
|
||||
return self.client.create_networking_config({
|
||||
network_name: self.client.create_endpoint_config(aliases=[self.name])
|
||||
for network_name in self.networks
|
||||
})
|
||||
|
||||
def build(self, no_cache=False, pull=False, force_rm=False):
|
||||
log.info('Building %s' % self.name)
|
||||
|
||||
|
|
|
@ -133,12 +133,8 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.client.exec_start(exc)
|
||||
return self.client.exec_inspect(exc)['ExitCode']
|
||||
|
||||
def lookup(self, container, service_name):
|
||||
exit_code = self.execute(container, [
|
||||
"nslookup",
|
||||
"{}_{}_1".format(self.project.name, service_name)
|
||||
])
|
||||
return exit_code == 0
|
||||
def lookup(self, container, hostname):
|
||||
return self.execute(container, ["nslookup", hostname]) == 0
|
||||
|
||||
def test_help(self):
|
||||
self.base_dir = 'tests/fixtures/no-composefile'
|
||||
|
@ -414,6 +410,9 @@ class CLITestCase(DockerClientTestCase):
|
|||
networks = list(container.get('NetworkSettings.Networks'))
|
||||
self.assertEqual(networks, [network['Name']])
|
||||
|
||||
for service in services:
|
||||
assert self.lookup(container, service.name)
|
||||
|
||||
def test_up_with_networks(self):
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
|
Loading…
Reference in New Issue