Skip to content

Commit 58641f0

Browse files
authored
Merge pull request containers#716 from Tayeh/images_cmd
add `podman-compose images` command
2 parents 09a8a3e + eea8bac commit 58641f0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

podman_compose.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,42 @@ async def compose_stats(compose, args):
28512851
pass
28522852

28532853

2854+
@cmd_run(podman_compose, "images", "List images used by the created containers")
2855+
async def compose_images(compose, args):
2856+
img_containers = [cnt for cnt in compose.containers if "image" in cnt]
2857+
data = []
2858+
if args.quiet is True:
2859+
for img in img_containers:
2860+
name = img["name"]
2861+
output = await compose.podman.output([], "images", ["--quiet", img["image"]])
2862+
data.append(output.decode("utf-8").split())
2863+
else:
2864+
data.append(["CONTAINER", "REPOSITORY", "TAG", "IMAGE ID", "SIZE", ""])
2865+
for img in img_containers:
2866+
name = img["name"]
2867+
output = await compose.podman.output(
2868+
[],
2869+
"images",
2870+
[
2871+
"--format",
2872+
"table " + name + " {{.Repository}} {{.Tag}} {{.ID}} {{.Size}}",
2873+
"-n",
2874+
img["image"],
2875+
],
2876+
)
2877+
data.append(output.decode("utf-8").split())
2878+
2879+
# Determine the maximum length of each column
2880+
column_widths = [max(map(len, column)) for column in zip(*data)]
2881+
2882+
# Print each row
2883+
for row in data:
2884+
# Format each cell using the maximum column width
2885+
formatted_row = [cell.ljust(width) for cell, width in zip(row, column_widths)]
2886+
formatted_row[-2:] = ["".join(formatted_row[-2:]).strip()]
2887+
print("\t".join(formatted_row))
2888+
2889+
28542890
###################
28552891
# command arguments parsing
28562892
###################
@@ -3285,6 +3321,11 @@ def compose_kill_parse(parser):
32853321
)
32863322

32873323

3324+
@cmd_parse(podman_compose, "images")
3325+
def compose_images_parse(parser):
3326+
parser.add_argument("-q", "--quiet", help="Only display images IDs", action="store_true")
3327+
3328+
32883329
@cmd_parse(podman_compose, ["stats"])
32893330
def compose_stats_parse(parser):
32903331
parser.add_argument(

0 commit comments

Comments
 (0)