import { useQuery } from "@tanstack/react-query"; import { Unplug } from "lucide-react"; import * as YML from "yaml"; import { getContainersUsingVolumeOptions } from "~/client/api-client/@tanstack/react-query.gen"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/client/components/ui/card"; import { CodeBlock } from "~/client/components/ui/code-block"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table"; import type { Volume } from "~/client/lib/types"; type Props = { volume: Volume; }; export const DockerTabContent = ({ volume }: Props) => { const yamlString = YML.stringify({ services: { nginx: { image: "nginx:latest", volumes: [`im-${volume.name}:/path/in/container`], }, }, volumes: { [`im-${volume.name}`]: { external: true, }, }, }); const dockerRunCommand = `docker run -v im-${volume.name}:/path/in/container nginx:latest`; const { data: containersData, isLoading, error, } = useQuery({ ...getContainersUsingVolumeOptions({ path: { name: volume.name } }), refetchInterval: 10000, refetchOnWindowFocus: true, }); const containers = containersData || []; const getStateClass = (state: string) => { switch (state) { case "running": return "bg-green-100 text-green-800"; case "exited": return "bg-orange-100 text-orange-800"; default: return "bg-gray-100 text-gray-800"; } }; return (
Plug-and-play Docker integration This volume can be used in your Docker Compose files by referencing it as an external volume. The example demonstrates how to mount the volume to a service (nginx in this case). Make sure to adjust the path inside the container to fit your application's needs
Alternatively, you can use the following command to run a Docker container with the volume mounted
Containers Using This Volume List of Docker containers mounting this volume. {isLoading &&
Loading containers...
} {error &&
Failed to load containers: {String(error)}
} {!isLoading && !error && containers.length === 0 && (

No Docker containers are currently using this volume.

)} {!isLoading && !error && containers.length > 0 && (
Name ID State Image {containers.map((container) => ( {container.name} {container.id.slice(0, 12)} {container.state} {container.image} ))}
)}
); };