docker_list_containers
List Docker containers to view their status, images, and ports for monitoring and management. Use the 'all' parameter to include stopped containers.
Instructions
List Docker containers with their status, image, and ports
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| all | No | Show all containers (default: only running) |
Implementation Reference
- src/tools/docker/containers.ts:4-25 (handler)The handler function implementation for listing docker containers.
export async function listContainers(args: Record<string, unknown>): Promise<string> { const docker = getDockerClient(); const all = (args.all as boolean) || false; const containers = await docker.listContainers({ all }); if (containers.length === 0) { return all ? "No containers found." : "No running containers found."; } const headers = ["ID", "NAME", "IMAGE", "STATUS", "PORTS"]; const rows = containers.map((c) => [ c.Id.substring(0, 12), (c.Names?.[0] || "").replace(/^\//, ""), c.Image, c.Status, (c.Ports || []).map((p) => p.PublicPort ? `${p.PublicPort}→${p.PrivatePort}/${p.Type}` : `${p.PrivatePort}/${p.Type}` ).join(", "), ]); return `Containers${all ? " (all)" : " (running)"}:\n\n${formatTable(headers, rows)}`; } - src/tools/docker/index.ts:8-17 (registration)Registration of the docker_list_containers tool.
{ name: "docker_list_containers", description: "List Docker containers with their status, image, and ports", inputSchema: { type: "object" as const, properties: { all: { type: "boolean", description: "Show all containers (default: only running)" }, }, }, },