Created
August 16, 2020 21:28
-
-
Save muyajil/da657245faadb1d7a033bfff664bced1 to your computer and use it in GitHub Desktop.
Display all docker-compose projects running in a summarized view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import subprocess | |
| from tabulate import tabulate | |
| out = subprocess.Popen(['docker','ps', '--format', '"table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.RunningFor}}\t{{.Ports}}"'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
| stdout, _ = out.communicate() | |
| stdout = stdout.decode('utf-8') | |
| lines = stdout.split('\n') | |
| table = [] | |
| for line in lines[:-1]: | |
| parts = line.split('\t') | |
| parts[0] = parts[0].split(' ')[1] | |
| project, container = parts[0].split('_', 1) | |
| container = container[:-2] | |
| image = parts[1] | |
| status = parts[2] | |
| uptime = parts[3] | |
| ports = parts[4].strip('"') | |
| table.append([project, container, image, status, ports]) | |
| table.sort(key=lambda x: x[0]+x[1]) | |
| print(tabulate(table, headers=["PROJECT", "CONTAINER", "IMAGE", "STATUS", "PORTS"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment