{"record":{"id":"61419b7576e9a384","repo":"coollabsio/coolify","slug":"container-not-found","errorCode":null,"errorMessage":"Container not found.","messagePattern":"Container not found\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"app/Livewire/Project/Shared/ExecuteContainerCommand.php","lineNumber":212,"sourceCode":"    #[On('connectToContainer')]\n    public function connectToContainer()\n    {\n        if ($this->selected_container === 'default') {\n            $this->dispatch('error', 'Please select a container.');\n\n            return;\n        }\n        try {\n            $this->authorize('canAccessTerminal');\n            // Validate container name format\n            if (! ValidationPatterns::isValidContainerName($this->selected_container)) {\n                throw new \\InvalidArgumentException('Invalid container name format');\n            }\n\n            // Verify container exists in our allowed list\n            $container = collect($this->containers)->firstWhere('container.Names', $this->selected_container);\n            if (is_null($container)) {\n                throw new \\RuntimeException('Container not found.');\n            }\n\n            // Verify server ownership and status\n            $server = data_get($container, 'server');\n            if (! $server || ! $server instanceof Server) {\n                throw new \\RuntimeException('Invalid server configuration.');\n            }\n\n            $this->authorize('view', $server);\n\n            if ($server->isForceDisabled()) {\n                throw new \\RuntimeException('Server is disabled.');\n            }\n\n            // Additional ownership verification based on resource type\n            $resourceServer = match ($this->type) {\n                'application' => $this->resource->destination->server,\n                'database' => $this->resource->destination->server,","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Livewire/Project/Shared/ExecuteContainerCommand.php#L194-L230","documentation":"After the format check passes, the component resolves the container via collect($this->containers)->firstWhere('container.Names', $this->selected_container). The $this->containers array is the list of Docker containers previously fetched for this resource's servers; a null match means the name is syntactically valid but no container in that allowed list carries it, so the terminal connection is refused with 'Container not found.'.","triggerScenarios":"The container was stopped, removed, or recreated with a new generated name between page render and clicking Connect (e.g. after a redeploy the app container now has a new hash suffix); the resource was moved to a different server/destination so the containers list no longer includes it; the containers property was never populated for this resource type; a replayed Livewire snapshot references an old name.","commonSituations":"Stale browser tab left open across a deployment; preview deployments that append PR/hash to container names; docker rm run manually on the host; scaling events that replace containers.","solutions":["Reload the page (or re-trigger the container list load) and select the container again from the refreshed dropdown","Verify the container actually runs on the target server: docker ps | grep <name>","If the container exists but is missing from the list, check the resource's destination/server wiring so it is queried on the right host","Re-run or restart the deployment so container names in the UI match Docker's current state"],"exampleFix":"// before\n$this->dispatch('connectToContainer', container: $this->selected_container);\n\n// after\n$this->loadContainers(); // re-fetch current list from Docker\nif (collect($this->containers)->firstWhere('container.Names', $this->selected_container)) {\n    $this->dispatch('connectToContainer', container: $this->selected_container);\n} else {\n    $this->dispatch('error', 'Container no longer exists - pick a new one.');\n}","handlingStrategy":"validation","validationCode":"$exists = collect($this->containers)\n    ->firstWhere('container.Names', $this->selected_container) !== null;\nif (! $exists) {\n    $this->dispatch('error', 'Container no longer exists.');\n    return;\n}","typeGuard":"/** @param mixed $value */\nfunction isLiveContainerEntry($value): bool\n{\n    return is_array($value)\n        && data_get($value, 'server') instanceof \\App\\Models\\Server\n        && filled(data_get($value, 'container.Names'));\n}","tryCatchPattern":"Catch \\RuntimeException in the action, dispatch('error', $e->getMessage()), and refresh the containers list so the dropdown self-heals instead of leaving stale options.","preventionTips":["Re-fetch the container list immediately before connecting rather than trusting the rendered snapshot","Re-select the container after any deployment that recreates containers","Verify with docker ps on the host when the UI insists a container is missing"],"tags":["docker","stale-state","livewire","terminal"],"backgroundTag":"stale-resource-reference","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}