Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(2): parse NDJSON output from docker compose ps

Juan Denis3f9884c055a5
diff --git a/backend/app/services/docker_service.py b/backend/app/services/docker_service.py
index 80a23921..f2313a1f 100644
--- a/backend/app/services/docker_service.py
+++ b/backend/app/services/docker_service.py
@@ -537,7 +537,11 @@ class DockerService:
@staticmethod
def compose_ps(project_path):
- """List Docker Compose services."""
+ """List Docker Compose services.
+
+ Note: docker compose ps --format json outputs NDJSON (one JSON object per line),
+ not a JSON array. We parse each line separately.
+ """
try:
result = subprocess.run(
['docker', 'compose', 'ps', '--format', 'json'],
@@ -545,7 +549,15 @@ class DockerService:
capture_output=True, text=True
)
if result.returncode == 0 and result.stdout.strip():
- return json.loads(result.stdout)
+ # Parse NDJSON - one JSON object per line
+ containers = []
+ for line in result.stdout.strip().split('\n'):
+ if line.strip():
+ try:
+ containers.append(json.loads(line))
+ except json.JSONDecodeError:
+ continue
+ return containers
return []
except Exception:
return []