#!/usr/bin/env python3 import subprocess, json cmd = ["/usr/bin/curl", "--unix-socket", "/var/run/docker.sock", "-s", "http://localhost/containers/json?all=1"] raw = subprocess.check_output(cmd, text=True) data = json.loads(raw) lines = [] for c in data: name = c.get("Names", ["?"])[0].lstrip("/") state = c.get("State", "?") status = c.get("Status", "?") image = c.get("Image", "?") lines.append(f"{name} | {state} | {status} | {image}") out = {"count": len(lines), "list": sorted(lines)} print(json.dumps(out, ensure_ascii=False))