mirror of https://github.com/docker/compose.git
Services can join 'bridge' or 'host'
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
e75629392d
commit
ca68c9faa4
|
@ -172,13 +172,16 @@ class Project(object):
|
|||
def get_networks(self, service_dict, network_definitions):
|
||||
networks = []
|
||||
for name in service_dict.pop('networks', ['default']):
|
||||
matches = [n for n in network_definitions if n.name == name]
|
||||
if matches:
|
||||
networks.append(matches[0].full_name)
|
||||
if name in ['bridge', 'host']:
|
||||
networks.append(name)
|
||||
else:
|
||||
raise ConfigurationError(
|
||||
'Service "{}" uses an undefined network "{}"'
|
||||
.format(service_dict['name'], name))
|
||||
matches = [n for n in network_definitions if n.name == name]
|
||||
if matches:
|
||||
networks.append(matches[0].full_name)
|
||||
else:
|
||||
raise ConfigurationError(
|
||||
'Service "{}" uses an undefined network "{}"'
|
||||
.format(service_dict['name'], name))
|
||||
return networks
|
||||
|
||||
def get_links(self, service_dict):
|
||||
|
|
|
@ -437,6 +437,25 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
assert 'Service "web" uses an undefined network "foo"' in result.stderr
|
||||
|
||||
def test_up_predefined_networks(self):
|
||||
filename = 'predefined-networks.yml'
|
||||
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
self._project = get_project(self.base_dir, [filename])
|
||||
|
||||
self.dispatch(['-f', filename, 'up', '-d'], None)
|
||||
|
||||
networks = [
|
||||
n for n in self.client.networks()
|
||||
if n['Name'].startswith('{}_'.format(self.project.name))
|
||||
]
|
||||
assert not networks
|
||||
|
||||
for name in ['bridge', 'host', 'none']:
|
||||
container = self.project.get_service(name).containers()[0]
|
||||
assert container.get('NetworkSettings.Networks').keys() == [name]
|
||||
assert container.get('HostConfig.NetworkMode') == name
|
||||
|
||||
def test_up_no_services(self):
|
||||
self.base_dir = 'tests/fixtures/no-services'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
version: 2
|
||||
|
||||
services:
|
||||
bridge:
|
||||
image: busybox
|
||||
command: top
|
||||
networks: ["bridge"]
|
||||
|
||||
host:
|
||||
image: busybox
|
||||
command: top
|
||||
networks: ["host"]
|
||||
|
||||
none:
|
||||
image: busybox
|
||||
command: top
|
||||
networks: []
|
Loading…
Reference in New Issue