diff --git a/autocompose.py b/autocompose.py index 4432648..7d78856 100644 --- a/autocompose.py +++ b/autocompose.py @@ -10,12 +10,14 @@ def main(): args = parser.parse_args() struct = {} - networks = [] + networks = set() for cname in args.cnames: - cfile, networks = generate(cname) - struct.update(cfile) + cfile, c_networks = generate(cname) - render(struct, args, networks) + struct.update(cfile) + networks.update(c_networks) + + render(struct, args, list(networks)) def render(struct, args, networks): @@ -94,12 +96,12 @@ def generate(cname): networks[network.attrs['Name']] = {'external': (not network.attrs['Internal'])} # Check for command and add it if present. - if cattrs['Config']['Cmd'] != None: - values['command'] = " ".join(cattrs['Config']['Cmd']), + if cattrs['Config']['Cmd'] is not None: + values['command'] = cattrs['Config']['Cmd'] # Check for exposed/bound ports and add them if needed. try: - expose_value = list(cattrs['Config']['ExposedPorts'].keys()) + expose_value = list(cattrs['Config']['ExposedPorts'].keys()) ports_value = [cattrs['HostConfig']['PortBindings'][key][0]['HostIp']+':'+cattrs['HostConfig']['PortBindings'][key][0]['HostPort']+':'+key for key in cattrs['HostConfig']['PortBindings']] # If bound ports found, don't use the 'expose' value.