chore: add container count to image details

This commit is contained in:
davidhorvat 2024-12-05 20:50:47 +01:00
parent 8cab528551
commit 6a16e71310

View file

@ -10,8 +10,18 @@ class GetServerDockerImageDetails
public static function run($server, $imageId)
{
$result = instant_remote_process(["docker inspect --format 'json' --type=image {$imageId}"], $server);
$imageDetailsRaw = instant_remote_process(["docker inspect --type=image {$imageId}"], $server);
$imageDetails = json_decode($imageDetailsRaw, true);
return json_decode($result, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return ['error' => 'Invalid JSON returned from Docker inspect', 'raw_output' => $imageDetailsRaw];
}
$containerCountRaw = instant_remote_process(["docker ps -q --filter ancestor={$imageId} | wc -l"], $server);
$containerCount = intval(trim($containerCountRaw)); // Convert to an integer
$imageDetails[0]['ContainerCount'] = $containerCount;
return $imageDetails;
}
}