diff --git a/compose/config/serialize.py b/compose/config/serialize.py index 5b36124d0..e364117e7 100644 --- a/compose/config/serialize.py +++ b/compose/config/serialize.py @@ -111,9 +111,9 @@ def denormalize_service_dict(service_dict, version, image_digest=None): ) if 'ports' in service_dict and version not in (V3_2,): - service_dict['ports'] = map( - lambda p: p.legacy_repr() if isinstance(p, types.ServicePort) else p, - service_dict['ports'] - ) + service_dict['ports'] = [ + p.legacy_repr() if isinstance(p, types.ServicePort) else p + for p in service_dict['ports'] + ] return service_dict diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index b7e4cc9bf..6bf4986ff 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -3837,3 +3837,15 @@ class SerializeTest(unittest.TestCase): serialized_service = serialized_config['services']['web'] assert secret_sort(serialized_service['secrets']) == secret_sort(service_dict['secrets']) assert 'secrets' in serialized_config + + def test_serialize_ports(self): + config_dict = config.Config(version='2.0', services=[ + { + 'ports': [types.ServicePort('80', '8080', None, None, None)], + 'image': 'alpine', + 'name': 'web' + } + ], volumes={}, networks={}, secrets={}) + + serialized_config = yaml.load(serialize_config(config_dict)) + assert '8080:80/tcp' in serialized_config['services']['web']['ports']