Skip to content

Commit e19c465

Browse files
authored
Merge pull request #38 from ostafen/master
Add -a/--all flag to list all containers
2 parents 0dfdac3 + d6ddded commit e19c465

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

autocompose.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
import sys, argparse, pyaml, docker
44
from collections import OrderedDict
55

6+
7+
def list_container_names():
8+
c = docker.from_env()
9+
return [container.name for container in c.containers.list(all=True)]
10+
11+
612
def main():
713
parser = argparse.ArgumentParser(description='Generate docker-compose yaml definition from running container.')
14+
parser.add_argument('-a', '--all', action='store_true', help='Include all active containers')
815
parser.add_argument('-v', '--version', type=int, default=3, help='Compose file version (1 or 3)')
916
parser.add_argument('cnames', nargs='*', type=str, help='The name of the container to process.')
1017
args = parser.parse_args()
1118

19+
container_names = args.cnames
20+
if args.all:
21+
container_names.extend(list_container_names())
22+
1223
struct = {}
1324
networks = {}
14-
for cname in args.cnames:
25+
for cname in container_names:
1526
cfile, c_networks = generate(cname)
1627

1728
struct.update(cfile)

0 commit comments

Comments
 (0)