mirror of https://github.com/docker/compose.git
Add support for specifying external port
This commit is contained in:
parent
120d57e856
commit
87c46e281c
|
@ -92,7 +92,6 @@ class TopLevelCommand(Command):
|
|||
}
|
||||
container = service.create_container(**container_options)
|
||||
stream = self.client.logs(container, stream=True)
|
||||
service.start_container(container, **container_options)
|
||||
for data in stream:
|
||||
if data is None:
|
||||
break
|
||||
|
|
|
@ -42,8 +42,13 @@ class Service(object):
|
|||
if container is None:
|
||||
container = self.create_container(**override_options)
|
||||
port_bindings = {}
|
||||
for port in container_options.get('ports', []):
|
||||
port_bindings[port] = None
|
||||
for port in self.options.get('ports', []):
|
||||
port = unicode(port)
|
||||
if ':' in port:
|
||||
internal_port, external_port = port.split(':', 1)
|
||||
port_bindings[int(internal_port)] = int(external_port)
|
||||
else:
|
||||
port_bindings[int(port)] = None
|
||||
self.client.start(
|
||||
container['Id'],
|
||||
links=self._get_links(),
|
||||
|
@ -85,6 +90,9 @@ class Service(object):
|
|||
number = self.next_container_number()
|
||||
container_options['name'] = make_name(self.name, number)
|
||||
|
||||
if 'ports' in container_options:
|
||||
container_options['ports'] = [unicode(p).split(':')[0] for p in container_options['ports']]
|
||||
|
||||
if 'build' in self.options:
|
||||
log.info('Building %s from %s...' % (self.name, self.options['build']))
|
||||
container_options['image'] = self.client.build(self.options['build'])[0]
|
||||
|
|
|
@ -87,5 +87,19 @@ class NameTestCase(DockerClientTestCase):
|
|||
container = service.start()
|
||||
self.client.wait(container)
|
||||
self.assertIn('success', self.client.logs(container))
|
||||
|
||||
|
||||
def test_start_container_creates_ports(self):
|
||||
service = self.create_service('web', ports=[8000])
|
||||
service.start_container()
|
||||
container = service.inspect()[0]
|
||||
self.assertIn('8000/tcp', container['HostConfig']['PortBindings'])
|
||||
self.assertNotEqual(container['HostConfig']['PortBindings']['8000/tcp'][0]['HostPort'], '8000')
|
||||
|
||||
def test_start_container_creates_fixed_external_ports(self):
|
||||
service = self.create_service('web', ports=['8000:8000'])
|
||||
service.start_container()
|
||||
container = service.inspect()[0]
|
||||
self.assertIn('8000/tcp', container['HostConfig']['PortBindings'])
|
||||
self.assertEqual(container['HostConfig']['PortBindings']['8000/tcp'][0]['HostPort'], '8000')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue