Fix ordering of port mapping

This commit is contained in:
Ben Firshman 2014-01-16 01:54:05 +00:00
parent d4000e07a9
commit 7a1fb3a8d2
2 changed files with 13 additions and 2 deletions

View File

@ -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'])

View File

@ -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')