Skip to content

Commit

Permalink
Merge pull request #38 from ostafen/master
Browse files Browse the repository at this point in the history
Add -a/--all flag to list all containers
  • Loading branch information
Red5d authored Apr 10, 2022
2 parents 0dfdac3 + d6ddded commit e19c465
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion autocompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
import sys, argparse, pyaml, docker
from collections import OrderedDict


def list_container_names():
c = docker.from_env()
return [container.name for container in c.containers.list(all=True)]


def main():
parser = argparse.ArgumentParser(description='Generate docker-compose yaml definition from running container.')
parser.add_argument('-a', '--all', action='store_true', help='Include all active containers')
parser.add_argument('-v', '--version', type=int, default=3, help='Compose file version (1 or 3)')
parser.add_argument('cnames', nargs='*', type=str, help='The name of the container to process.')
args = parser.parse_args()

container_names = args.cnames
if args.all:
container_names.extend(list_container_names())

struct = {}
networks = {}
for cname in args.cnames:
for cname in container_names:
cfile, c_networks = generate(cname)

struct.update(cfile)
Expand Down

0 comments on commit e19c465

Please sign in to comment.