diff --git a/compose/config/types.py b/compose/config/types.py index be26971c4..c410343b8 100644 --- a/compose/config/types.py +++ b/compose/config/types.py @@ -343,7 +343,7 @@ class ServicePort(namedtuple('_ServicePort', 'target published protocol mode ext def normalize_port_dict(port): return '{external_ip}{has_ext_ip}{published}{is_pub}{target}/{protocol}'.format( published=port.get('published', ''), - is_pub=(':' if port.get('published') or port.get('external_ip') else ''), + is_pub=(':' if port.get('published') is not None or port.get('external_ip') else ''), target=port.get('target'), protocol=port.get('protocol', 'tcp'), external_ip=port.get('external_ip', ''), diff --git a/tests/unit/config/types_test.py b/tests/unit/config/types_test.py index 10b698fe3..3a43f727b 100644 --- a/tests/unit/config/types_test.py +++ b/tests/unit/config/types_test.py @@ -81,6 +81,12 @@ class TestServicePort(object): 'external_ip': '1.1.1.1', } + def test_repr_published_port_0(self): + port_def = '0:4000' + ports = ServicePort.parse(port_def) + assert len(ports) == 1 + assert ports[0].legacy_repr() == port_def + '/tcp' + def test_parse_port_range(self): ports = ServicePort.parse('25000-25001:4000-4001') assert len(ports) == 2