diff --git a/app/Jobs/CleanupOrphanedPreviewContainersJob.php b/app/Jobs/CleanupOrphanedPreviewContainersJob.php index 790ad1489..5d3bed457 100644 --- a/app/Jobs/CleanupOrphanedPreviewContainersJob.php +++ b/app/Jobs/CleanupOrphanedPreviewContainersJob.php @@ -179,6 +179,16 @@ private function isOrphanedContainer($container): bool private function removeContainer($container, Server $server): void { $containerName = data_get($container, 'Names'); + + if (empty($containerName)) { + Log::warning('CleanupOrphanedPreviewContainersJob - Cannot remove container: missing container name', [ + 'container_data' => $container, + 'server' => $server->name, + ]); + + return; + } + $applicationId = $this->extractApplicationId($container); $pullRequestId = $this->extractPullRequestId($container); @@ -189,9 +199,11 @@ private function removeContainer($container, Server $server): void 'server' => $server->name, ]); + $escapedContainerName = escapeshellarg($containerName); + try { instant_remote_process( - ["docker rm -f {$containerName}"], + ["docker rm -f {$escapedContainerName}"], $server, false );