Skip to content

Modern Docker Management, Designed for Everyone

24.2 KB
Raw Blame
<script lang="ts">
	import { goto, refreshAll } from '$app/navigation';
	import { page } from '$app/state';
	import { useQueryClient } from '@tanstack/svelte-query';
	import { mode } from 'mode-watcher';
	import { onMount, tick } from 'svelte';
	import { toast } from 'svelte-sonner';
	import { parse as parseYaml } from 'yaml';

	import type { ActionButton } from '#lib/components/action-button-group/types.js';
	import ActionButtons from '#lib/components/action-buttons.svelte';
	import EnvironmentCell from '#lib/components/arcane-table/cells/environment-cell.svelte';
	import IconImage from '#lib/components/icon-image.svelte';
	import ResourceNotFound from '#lib/components/resource-not-found.svelte';
	import { Badge } from '#lib/components/ui/badge/index.js';
	import * as Tabs from '#lib/components/ui/tabs/index.js';
	import { useUrlTab } from '#lib/hooks/use-url-tab.svelte.js';
	import {
		VolumesIcon,
		FileTextIcon,
		SettingsIcon,
		NetworksIcon,
		TerminalIcon,
		ContainersIcon,
		StatsIcon,
		CodeIcon,
		InspectIcon,
		HealthIcon,
		LayoutListIcon
	} from '#lib/icons/index.js';
	import { EditIcon, ProjectsIcon } from '#lib/icons/index.js';
	import TabbedPageLayout from '#lib/layouts/tabbed-page-layout.svelte';
	import { m } from '#lib/paraglide/messages.js';
	import { queryKeys } from '#lib/query/query-keys.js';
	import { APIError } from '#lib/services/api-service.js';
	import { containerService } from '#lib/services/container-service.js';
	import { projectWorkspaceService } from '#lib/services/project-workspace-service.js';
	import { activityStore } from '#lib/stores/activity.store.svelte.js';
	import settingsStore from '#lib/stores/config-store.svelte.js';
	import type { ContainerDetailsDto, ContainerNetworkSettings, ContainerStats as ContainerStatsType } from '#lib/types/docker.js';
	import type { IncludeFile } from '#lib/types/swarm.js';
	import { extractApiErrorMessage } from '#lib/utils/api.js';
	import { hasPermission } from '#lib/utils/auth.js';
	import { runContainerLifecycleAction, confirmAndUpdateContainer } from '#lib/utils/container-actions.js';
	import { isAutoUpdateLabelDisabled } from '#lib/utils/container-auto-update.js';
	import { createContainerUpdateActivityTracker } from '#lib/utils/container-update-activities.js';
	import { calculateMemoryUsage, getCustomHostname, getThemedIconUrl } from '#lib/utils/docker.js';
	import { environmentHref, listScopes } from '#lib/utils/environments.js';
	import { bytes } from '#lib/utils/formatting.js';
	import { quadletUnitHref } from '#lib/utils/podman.js';
	import { tryCatch } from '#lib/utils/try-catch.js';

	import ContainerCommitDialog from '../components/container-commit-dialog.svelte';
	import ContainerComposePanel from '../components/container-compose-panel.svelte';
	import ContainerConfiguration from '../components/container-configuration.svelte';
	import ContainerDetailStatsSync from '../components/container-detail-stats-sync.svelte';
	import ContainerHealthcheck from '../components/container-healthcheck.svelte';
	import ContainerInspect from '../components/container-inspect.svelte';
	import ContainerLogsPanel from '../components/container-logs-panel.svelte';
	import ContainerNetwork from '../components/container-network.svelte';
	import ContainerOverview from '../components/container-overview.svelte';
	import ContainerProcesses from '../components/container-processes.svelte';
	import ContainerShell from '../components/container-shell.svelte';
	import ContainerStats from '../components/container-stats.svelte';
	import ContainerStorage from '../components/container-storage.svelte';
	import KillContainerDialog from '../components/kill-container-dialog.svelte';
	import { getContainerStatusLabel } from '../container-table.helpers';
	let { data } = $props();
	const queryClient = useQueryClient();
	let container = $derived(data?.container as ContainerDetailsDto);
	let stats = $state(null as ContainerStatsType | null);

	let autoScrollLogs = $state(true);
	let hasInitialStatsLoaded = $state(false);
	let statsError = $state(false);

	// Auto-update: the Docker label controls the state when set (not toggleable via UI).
	// The status itself comes from the container response; older agents omit it.
	const autoUpdateLabelControlled = $derived(isAutoUpdateLabelDisabled(container?.labels));
	const autoUpdateStatusAvailable = $derived(typeof container?.autoUpdateEnabled === 'boolean');
	const autoUpdateEnabled = $derived(container?.autoUpdateEnabled === true);

	async function refreshContainerDetails() {
		await Promise.all([
			queryClient.invalidateQueries({ queryKey: queryKeys.containers.all }),
			queryClient.invalidateQueries({ queryKey: queryKeys.containers.detail(currentEnvId, container.id) })
		]);
		await refreshAll();
	}

	const cleanContainerName = (name: string | undefined): string => {
		if (!name) return m.common_not_found_title({ resource: m.containers() });
		return name.replace(/^\/+/, '');
	};

	const containerDisplayName = $derived(cleanContainerName(container?.name));
	const containerIconUrl = $derived(getThemedIconUrl(container, mode.current));

	const calculateCPUPercent = (statsData: ContainerStatsType | null): number => {
		if (!statsData || !statsData.cpu_stats || !statsData.precpu_stats) {
			return 0;
		}

		const cpuDelta = statsData.cpu_stats.cpu_usage.total_usage - (statsData.precpu_stats.cpu_usage?.total_usage || 0);
		const systemDelta = statsData.cpu_stats.system_cpu_usage - (statsData.precpu_stats.system_cpu_usage || 0);

		if (systemDelta > 0 && cpuDelta > 0) {
			const cpuPercent = (cpuDelta / systemDelta) * 100.0;
			return Math.min(Math.max(cpuPercent, 0), 100);
		}
		return 0;
	};

	const cpuUsagePercent = $derived(calculateCPUPercent(stats));

	const cpuLimit = $derived.by(() => {
		if (container?.hostConfig?.nanoCpus) {
			return container.hostConfig.nanoCpus / 1e9;
		}
		return stats?.cpu_stats?.online_cpus || 0;
	});
	const memoryUsageBytes = $derived(calculateMemoryUsage(stats));
	const memoryLimitBytes = $derived(stats?.memory_stats?.limit || 0);
	const memoryUsageFormatted = $derived(bytes.format(memoryUsageBytes || 0) || '0 B');
	const memoryLimitFormatted = $derived(bytes.format(memoryLimitBytes || 0) || '0 B');
	const memoryUsagePercent = $derived(memoryLimitBytes > 0 ? (memoryUsageBytes / memoryLimitBytes) * 100 : 0);

	const getPrimaryIpAddress = (networkSettings: ContainerNetworkSettings | undefined | null): string => {
		if (!networkSettings?.networks) return 'N/A';

		for (const networkName in networkSettings.networks) {
			const net = networkSettings.networks[networkName];
			if (net?.ipAddress) return net.ipAddress;
		}
		return 'N/A';
	};

	const primaryIpAddress = $derived(getPrimaryIpAddress(container?.networkSettings));

	async function refreshData() {
		await refreshAll();
	}

	const hasEnvVars = $derived(!!(container?.config?.env && container.config.env.length > 0));
	const hasPorts = $derived(!!(container?.ports && container.ports.length > 0));
	const hasLabels = $derived(!!(container?.labels && Object.keys(container.labels).length > 0));
	const showConfiguration = $derived(hasEnvVars || hasLabels);

	const hasNetworks = $derived(
		!!(container?.networkSettings?.networks && Object.keys(container.networkSettings.networks).length > 0)
	);
	// A container with a hostname but no networks or ports still has something to show here.
	const hasCustomHostname = $derived(!!(container && getCustomHostname(container)));
	const showNetworkTab = $derived(hasNetworks || hasPorts || hasCustomHostname);
	const hasMounts = $derived(!!(container?.mounts && container.mounts.length > 0));
	const currentEnvId = $derived(data.envId);
	const canViewLogs = $derived(hasPermission('containers:logs', currentEnvId));
	const canExecShell = $derived(hasPermission('containers:exec', currentEnvId));
	const canPauseContainer = $derived(hasPermission('containers:pause', currentEnvId));
	const canUpdateContainer = $derived(hasPermission('containers:autoupdate', currentEnvId));
	const canEditContainer = $derived(
		hasPermission('containers:edit', currentEnvId) && !container?.composeInfo && !container?.redeployDisabled
	);
	const canKillContainer = $derived(hasPermission('containers:kill', currentEnvId));
	const canCommitImage = $derived(hasPermission('images:commit', currentEnvId));
	const canConvertToCompose = $derived(
		hasPermission('projects:create', currentEnvId) &&
			!container?.composeInfo &&
			settingsStore.current?.experimentalFeaturesEnabled === true
	);
	const containerStatus = $derived(container?.state?.status ?? '');
	const isContainerRunning = $derived(containerStatus === 'running' || !!container?.state?.running);
	const isContainerPaused = $derived(containerStatus === 'paused');

	let killDialogOpen = $state(false);
	let commitDialogOpen = $state(false);
	let lifecycleStatus = $state<'pausing' | 'unpausing' | ''>('');
	const isLifecycleActionPending = $derived(lifecycleStatus !== '');

	// The details response carries the stored check for this container's current
	// policy; an older agent that omits it reports no status rather than "up to date".
	const updateInfo = $derived(canUpdateContainer ? (container?.updateInfo ?? null) : null);
	let updateLoading = $state(false);
	let updateViewMounted = false;
	const updateActivities = createContainerUpdateActivityTracker(
		() => [currentEnvId],
		() => {
			void refreshAfterUpdate();
		},
		() => container.id
	);
	onMount(() => {
		updateViewMounted = true;
		const unsubscribe = activityStore.subscribeActivities(updateActivities.observe);
		return () => {
			updateViewMounted = false;
			unsubscribe();
		};
	});

	async function refreshAfterUpdate() {
		const environmentId = currentEnvId;
		const containerId = container.id;
		const result = await tryCatch(containerService.getContainerForEnvironment(environmentId, containerId));
		if (!updateViewMounted || environmentId !== currentEnvId || containerId !== container.id) return;
		if (result.error instanceof APIError && result.error.status === 404) {
			await Promise.all(
				listScopes([environmentId]).map((scope) => queryClient.invalidateQueries({ queryKey: ['containers', scope] }))
			);
			if (!updateViewMounted || environmentId !== currentEnvId || containerId !== container.id) return;
			await goto('/containers');
			return;
		}
		if (result.error !== null) {
			toast.error(m.common_refresh_failed({ resource: m.containers() }), {
				description: extractApiErrorMessage(result.error)
			});
			return;
		}
		await Promise.all([
			...listScopes([environmentId]).flatMap((scope) => [
				queryClient.invalidateQueries({ queryKey: ['containers', scope] }),
				queryClient.invalidateQueries({ queryKey: ['projects', scope] })
			]),
			queryClient.invalidateQueries({ queryKey: queryKeys.containers.detail(environmentId, containerId) }),
			queryClient.invalidateQueries({ queryKey: queryKeys.projects.environment(environmentId) })
		]);
		if (updateViewMounted && environmentId === currentEnvId && containerId === container.id) await refreshAll();
	}

	function handleUpdateContainer() {
		if (!container) return;
		confirmAndUpdateContainer({
			containerId: container.id,
			containerName: containerDisplayName,
			environmentId: currentEnvId,
			setLoading: (loading) => {
				updateLoading = loading;
			},
			onRefresh: refreshAfterUpdate,
			onAccepted: (activity) => {
				if (updateViewMounted) updateActivities.accept(activity);
			}
		});
	}

	async function handlePauseContainer() {
		if (!container || isLifecycleActionPending) return;
		await runContainerLifecycleAction({
			action: 'pause',
			containerId: container.id,
			environmentId: currentEnvId,
			setStatus: (status) => {
				lifecycleStatus = status === 'pausing' ? status : '';
			},
			onRefresh: refreshContainerDetails
		});
	}

	async function handleUnpauseContainer() {
		if (!container || isLifecycleActionPending) return;
		await runContainerLifecycleAction({
			action: 'unpause',
			containerId: container.id,
			environmentId: currentEnvId,
			setStatus: (status) => {
				lifecycleStatus = status === 'unpausing' ? status : '';
			},
			onRefresh: refreshContainerDetails
		});
	}
	const showStats = $derived(!!container?.state?.running);
	const showShell = $derived(!!container?.state?.running && canExecShell);
	const hasHealthcheck = $derived(
		!!(container?.config?.healthcheck?.test && container.config.healthcheck.test.length > 0) || !!container?.state?.health
	);

	const project = $derived(data?.project ?? null);
	const composeInfo = $derived(container?.composeInfo ?? null);
	const quadletHref = $derived(quadletUnitHref(container?.labels, currentEnvId));
	const composeServiceName = $derived(composeInfo?.serviceName ?? '');
	const rootComposeFilename = $derived.by(() => {
		const cf = composeInfo?.configFiles;
		if (!cf) return 'compose.yml';
		const first = cf.split(',')[0]?.trim() ?? '';
		return first.split('/').pop() || 'compose.yml';
	});

	// Find which file (root compose or an include file) directly defines this service.
	// Returns { includeFile: null } for root compose, { includeFile: <file> } for a sub-file,
	// or null if the service isn't found anywhere (hides the tab).
	//
	// Include file content is lazy-loaded, so fetch it from Project Workspace on
	// demand and stop as soon as the service is found.
	const hasServiceInContent = (content: string, serviceName: string): boolean => {
		try {
			const parsed = parseYaml(content) as Record<string, unknown> | null;
			return !!(parsed?.['services'] && (parsed['services'] as Record<string, unknown>)[serviceName]);
		} catch {
			return false;
		}
	};

	async function resolveServiceComposeSource(
		proj: typeof project,
		svcName: string,
		info: typeof composeInfo
	): Promise<{ includeFile: IncludeFile | null } | null> {
		if (!proj || !svcName || !info) return null;

		// Check root compose first (content is always present)
		if (proj.composeContent && hasServiceInContent(proj.composeContent, svcName)) {
			return { includeFile: null };
		}

		// Lazy-fetch include file contents one at a time until we find the service
		const includes = proj.includeFiles ?? [];
		if (includes.length === 0) return null;

		const envId = currentEnvId;

		for (const f of includes) {
			if (f.content && hasServiceInContent(f.content, svcName)) {
				return { includeFile: f };
			}
			const sourceResult = await tryCatch(
				(async () => {
					const loaded = await projectWorkspaceService.getWorkspaceFile(proj.id, f.relativePath, envId);
					if (loaded?.content && hasServiceInContent(loaded.content, svcName)) {
						return { includeFile: { ...f, content: loaded.content } };
					}
				})()
			);
			if (sourceResult.error === null && sourceResult.data) return sourceResult.data;
		}
		return null;
	}

	const serviceComposeSourcePromise = $derived(resolveServiceComposeSource(project, composeServiceName, composeInfo));

	const showComposeTab = $derived(!!composeInfo && !!project);

	const urlTab = useUrlTab({
		tabs: () => [
			{ value: 'overview', label: m.common_overview(), icon: ContainersIcon },
			{ value: 'stats', label: m.containers_nav_metrics(), icon: StatsIcon, visible: showStats },
			{ value: 'processes', label: m.containers_processes_title(), icon: LayoutListIcon },
			{ value: 'logs', label: m.common_logs(), icon: FileTextIcon, visible: canViewLogs },
			{ value: 'shell', label: m.common_shell(), icon: TerminalIcon, visible: showShell },
			{ value: 'healthcheck', label: m.containers_nav_healthcheck(), icon: HealthIcon, visible: hasHealthcheck },
			{ value: 'config', label: m.common_configuration(), icon: SettingsIcon, visible: showConfiguration },
			{ value: 'network', label: m.resource_networks_cap(), icon: NetworksIcon, visible: showNetworkTab },
			{ value: 'storage', label: m.storage(), icon: VolumesIcon, visible: hasMounts },
			{ value: 'compose', label: m.compose(), icon: CodeIcon, visible: showComposeTab },
			{ value: 'inspect', label: m.common_inspect(), icon: InspectIcon }
		],
		defaultTab: () => 'overview'
	});
	const activeTab = $derived(urlTab.value);

	function onTabChange(value: string) {
		urlTab.select(value);
	}

	async function navigateToNetworkPortMappings() {
		if (!showNetworkTab) return;

		urlTab.select('network');
		await tick();

		requestAnimationFrame(() => {
			document.getElementById('container-port-mappings')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
		});
	}

	const backUrl = $derived.by(() => {
		const from = page.url.searchParams.get('from');
		const projectId = page.url.searchParams.get('projectId');

		if (from === 'project' && projectId) {
			return environmentHref(`/projects/${projectId}`, currentEnvId);
		}

		return '/containers';
	});

	const containerExtraActions = $derived.by((): ActionButton[] => {
		if (!container) return [];
		const list: ActionButton[] = [];
		if (canEditContainer) {
			list.push({
				id: 'edit',
				action: 'edit',
				label: m.common_edit(),
				icon: EditIcon,
				group: 'manage',
				href: environmentHref(`/containers/${container.id}/edit`, currentEnvId)
			});
		}
		if (canConvertToCompose) {
			list.push({
				id: 'convert',
				action: 'base',
				label: m.compose_convert_action(),
				icon: ProjectsIcon,
				group: 'manage',
				href: `/projects/new?fromContainers=${container.id}&fromEnv=${encodeURIComponent(currentEnvId)}`
			});
		}
		if (canUpdateContainer && updateInfo?.hasUpdate) {
			list.push({
				id: 'update',
				action: 'update',
				label: m.update_container(),
				group: 'manage',
				loading: updateLoading,
				onclick: handleUpdateContainer
			});
		}
		if (canPauseContainer && (isContainerPaused || isContainerRunning)) {
			list.push({
				id: 'pause',
				action: isContainerPaused ? 'unpause' : 'pause',
				label: isContainerPaused ? m.common_unpause() : m.common_pause(),
				group: 'lifecycle',
				loading: lifecycleStatus !== '',
				disabled: isLifecycleActionPending,
				onclick: isContainerPaused ? handleUnpauseContainer : handlePauseContainer
			});
		}
		if (canCommitImage) {
			list.push({
				id: 'commit',
				action: 'commit',
				label: m.commit(),
				group: 'manage',
				onclick: () => (commitDialogOpen = true)
			});
		}
		if (canKillContainer && (isContainerRunning || isContainerPaused)) {
			list.push({
				id: 'kill',
				action: 'kill',
				label: m.common_kill(),
				group: 'danger',
				destructive: true,
				disabled: isLifecycleActionPending,
				onclick: () => (killDialogOpen = true)
			});
		}
		return list;
	});
</script>

{#snippet containerHeader(container: ContainerDetailsDto)}
	<div class="flex flex-wrap items-center gap-x-2 gap-y-1">
		<IconImage
			src={containerIconUrl}
			alt={containerDisplayName}
			fallback={ContainersIcon}
			class="size-5"
			containerClass="size-9"
		/>
		<h1 class="max-w-40 min-w-0 truncate text-lg font-semibold sm:max-w-56 md:max-w-72 lg:max-w-88" title={containerDisplayName}>
			{containerDisplayName}
		</h1>
		{#if container?.state}
			<Badge
				variant={container.state.status === 'running' ? 'green' : container.state.status === 'exited' ? 'red' : 'amber'}
				minWidth="20">{getContainerStatusLabel(container.state.status)}</Badge
			>
		{/if}
		<EnvironmentCell value={currentEnvId} />
		{#if updateInfo?.hasUpdate}
			<Badge variant="amber" minWidth="20">{m.sidebar_update_available()}</Badge>
		{/if}
		{#if quadletHref}
			<Badge variant="purple" size="sm" href={quadletHref} title={m.podman_quadlet_update_disabled()}>
				{m.podman_managed_by_quadlet()}
			</Badge>
		{/if}
		{#if project && composeInfo}
			<Badge
				variant="gray"
				size="sm"
				href={environmentHref(`/projects/${project.id}`, currentEnvId)}
				title={m.projects_title()}
				class="max-w-40"
			>
				<span class="block min-w-0 truncate">
					{composeInfo.projectName}
				</span>
			</Badge>
		{/if}
	</div>
{/snippet}

{#snippet containerComposeTab()}
	{#await serviceComposeSourcePromise then serviceComposeSource}
		{#if project && serviceComposeSource}
			<Tabs.Content value="compose" class="h-full min-h-0">
				{#key `${currentEnvId}:${project?.id}-${serviceComposeSource?.includeFile?.relativePath ?? 'root'}`}
					<ContainerComposePanel
						{project}
						environmentId={currentEnvId}
						serviceName={composeServiceName}
						includeFile={serviceComposeSource.includeFile}
						rootFilename={rootComposeFilename}
					/>
				{/key}
			</Tabs.Content>
		{/if}
	{/await}
{/snippet}

{#snippet containerTabs(container: ContainerDetailsDto, activeTab: string)}
	<Tabs.Content value="overview" class="h-full">
		<ContainerOverview
			{container}
			environmentId={currentEnvId}
			{primaryIpAddress}
			{autoUpdateEnabled}
			{autoUpdateLabelControlled}
			{autoUpdateStatusAvailable}
			onAutoUpdateChange={refreshContainerDetails}
			onViewPortMappings={showNetworkTab ? navigateToNetworkPortMappings : undefined}
			onViewStorage={hasMounts ? () => onTabChange('storage') : undefined}
			onViewNetworks={showNetworkTab ? () => onTabChange('network') : undefined}
		/>
	</Tabs.Content>

	{#if showStats}
		<Tabs.Content value="stats" class="h-full">
			{#if activeTab === 'stats'}
				<ContainerStats
					{container}
					{stats}
					{cpuUsagePercent}
					{cpuLimit}
					{memoryUsageFormatted}
					{memoryLimitFormatted}
					{memoryUsagePercent}
					loading={!hasInitialStatsLoaded}
					streamError={statsError}
				/>
			{/if}
		</Tabs.Content>
	{/if}

	<Tabs.Content value="processes" class="h-full">
		{#if activeTab === 'processes'}
			<ContainerProcesses containerId={container.id} environmentId={currentEnvId} status={containerStatus} />
		{/if}
	</Tabs.Content>

	<Tabs.Content value="logs" class="h-full">
		{#if activeTab === 'logs'}
			{#key `${currentEnvId}:${container?.id}`}
				<ContainerLogsPanel
					containerId={container?.id}
					environmentId={currentEnvId}
					{stats}
					{hasInitialStatsLoaded}
					isRunning={!!container.state?.running}
					{cpuLimit}
					bind:autoScroll={autoScrollLogs}
				/>
			{/key}
		{/if}
	</Tabs.Content>

	{#if showShell}
		<Tabs.Content value="shell" class="h-full">
			{#if activeTab === 'shell'}
				<ContainerShell
					containerId={container?.id}
					environmentId={currentEnvId}
					labels={container?.labels}
					name={container?.name}
				/>
			{/if}
		</Tabs.Content>
	{/if}

	{#if hasHealthcheck}
		<Tabs.Content value="healthcheck" class="h-full">
			<ContainerHealthcheck {container} />
		</Tabs.Content>
	{/if}

	{#if showConfiguration}
		<Tabs.Content value="config" class="h-full">
			<ContainerConfiguration {container} {hasEnvVars} {hasLabels} />
		</Tabs.Content>
	{/if}

	{#if showNetworkTab}
		<Tabs.Content value="network" class="h-full">
			<ContainerNetwork {container} environmentId={currentEnvId} />
		</Tabs.Content>
	{/if}

	{#if hasMounts}
		<Tabs.Content value="storage" class="h-full">
			<ContainerStorage {container} />
		</Tabs.Content>
	{/if}

	{@render containerComposeTab()}

	<Tabs.Content value="inspect" class="h-full">
		<ContainerInspect {container} />
	</Tabs.Content>
{/snippet}

{#if container}
	{#key `${currentEnvId}:${container.id}`}
		<ContainerDetailStatsSync
			containerId={container.id}
			environmentId={currentEnvId}
			enabled={(activeTab === 'stats' || activeTab === 'logs') && !!container.state?.running}
			bind:stats
			bind:hasInitialStatsLoaded
			bind:statsError
		/>
	{/key}

	<TabbedPageLayout {backUrl} backLabel={m.common_back()} tabItems={urlTab.items} selectedTab={activeTab} {onTabChange}>
		{#snippet headerInfo()}
			{@render containerHeader(container)}
		{/snippet}

		{#snippet headerActions()}
			<ActionButtons
				id={container.id}
				environmentId={currentEnvId}
				name={containerDisplayName}
				type="container"
				itemState={container.state?.running ? 'running' : 'stopped'}
				disableRedeploy={!!container.redeployDisabled}
				extraActions={containerExtraActions}
				onActionComplete={refreshContainerDetails}
			/>
		{/snippet}

		{#snippet tabContent(activeTab)}
			{@render containerTabs(container, activeTab)}
		{/snippet}
	</TabbedPageLayout>

	{#if killDialogOpen && canKillContainer && (isContainerRunning || isContainerPaused)}
		<KillContainerDialog
			containerId={container.id}
			containerName={containerDisplayName}
			environmentId={currentEnvId}
			onClose={() => (killDialogOpen = false)}
			onComplete={() => {
				killDialogOpen = false;
				return refreshContainerDetails();
			}}
		/>
	{/if}
	{#if commitDialogOpen && canCommitImage}
		<ContainerCommitDialog
			bind:open={commitDialogOpen}
			containerId={container.id}
			containerName={containerDisplayName}
			environmentId={currentEnvId}
			onCommitted={refreshContainerDetails}
		/>
	{/if}
{:else}
	<ResourceNotFound resource={m.container()} resourceListTitle={m.containers()} backHref="/containers" onRetry={refreshData} />
{/if}