From a9a9f0f30f9571b737d4ec183138804b011ea9f1 Mon Sep 17 00:00:00 2001 From: Furox-Art <177975472+Furox-Art@users.noreply.github.com> Date: Wed, 30 Sep 2026 03:03:03 +0300 Subject: [PATCH] fix(api): respect service_name query param in application logs endpoint GET /applications/{uuid}/logs ignored service_name and always returned logs from the first container, so 'coolify app logs --service' could show logs from the wrong Compose service. When service_name is present, select the container whose labels contain the matching com.docker.compose.service entry and 404 when nothing matches. --- .../Api/ApplicationsController.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php index c45e03a281..6e82c01945 100644 --- a/app/Http/Controllers/Api/ApplicationsController.php +++ b/app/Http/Controllers/Api/ApplicationsController.php @@ -2472,6 +2472,13 @@ class ApplicationsController extends Controller required: false, schema: new OA\Schema(type: 'boolean', default: false), ), + new OA\Parameter( + name: 'service_name', + in: 'query', + description: 'For Docker Compose applications, return logs only from the Compose service with this name. Returns 404 when no running container matches. Ignored for non-Compose applications.', + required: false, + schema: new OA\Schema(type: 'string'), + ), ], responses: [ new OA\Response( @@ -2597,7 +2604,27 @@ class ApplicationsController extends Controller ], 400); } - $container = $containers->first(); + $serviceName = $request->query('service_name'); + if (filled($serviceName)) { + $matchingContainer = $containers->first(function ($container) use ($serviceName) { + $labels = data_get($container, 'Labels'); + + return $labels !== null && preg_match( + '/(?:^|,)com\.docker\.compose\.service='.preg_quote($serviceName, '/').'(?:,|$)/', + $labels + ) === 1; + }); + + if (! $matchingContainer) { + return response()->json([ + 'message' => "No running container found for service_name '{$serviceName}'.", + ], 404); + } + + $container = $matchingContainer; + } else { + $container = $containers->first(); + } $status = getContainerStatus($application->destination->server, $container['Names']); if ($status !== 'running') {