mirror of https://github.com/docker/compose.git
Fix ordering of port mapping
This commit is contained in:
parent
d4000e07a9
commit
7a1fb3a8d2
|
@ -86,7 +86,7 @@ class Service(object):
|
|||
for port in options['ports']:
|
||||
port = str(port)
|
||||
if ':' in port:
|
||||
internal_port, external_port = port.split(':', 1)
|
||||
external_port, internal_port = port.split(':', 1)
|
||||
port_bindings[int(internal_port)] = int(external_port)
|
||||
else:
|
||||
port_bindings[int(port)] = None
|
||||
|
@ -134,7 +134,13 @@ class Service(object):
|
|||
container_options['name'] = self.next_container_name(one_off)
|
||||
|
||||
if 'ports' in container_options:
|
||||
container_options['ports'] = [str(p).split(':')[0] for p in container_options['ports']]
|
||||
ports = []
|
||||
for port in container_options['ports']:
|
||||
port = str(port)
|
||||
if ':' in port:
|
||||
port = port.split(':')[-1]
|
||||
ports.append(port)
|
||||
container_options['ports'] = ports
|
||||
|
||||
if 'volumes' in container_options:
|
||||
container_options['volumes'] = dict((v.split(':')[1], {}) for v in container_options['volumes'])
|
||||
|
|
|
@ -157,4 +157,9 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertIn('8000/tcp', container['HostConfig']['PortBindings'])
|
||||
self.assertEqual(container['HostConfig']['PortBindings']['8000/tcp'][0]['HostPort'], '8000')
|
||||
|
||||
def test_start_container_creates_fixed_external_ports_when_it_is_different_to_internal_port(self):
|
||||
service = self.create_service('web', ports=['8001:8000'])
|
||||
container = service.start_container().inspect()
|
||||
self.assertIn('8000/tcp', container['HostConfig']['PortBindings'])
|
||||
self.assertEqual(container['HostConfig']['PortBindings']['8000/tcp'][0]['HostPort'], '8001')
|
||||
|
||||
|
|
Loading…
Reference in New Issue