docker_container_logs
Fetch Docker container logs to monitor application performance, troubleshoot errors, and analyze system behavior by retrieving log entries from specified containers.
Instructions
Fetch logs from a Docker container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Container ID or name | |
| tail | No | Number of lines from end (default: 100) | |
| since | No | Unix timestamp to start from |
Implementation Reference
- src/tools/docker/containers.ts:64-87 (handler)The containerLogs function retrieves logs from a Docker container using the Docker SDK.
export async function containerLogs(args: Record<string, unknown>): Promise<string> { const docker = getDockerClient(); const id = args.id as string || args.name as string; if (!id) throw new Error("Container ID or name is required"); const tail = (args.tail as number) || 100; const since = args.since as number | undefined; const container = docker.getContainer(id); const logs = await container.logs({ stdout: true, stderr: true, tail, since, timestamps: true, }); const logStr = typeof logs === "string" ? logs : logs.toString("utf-8"); if (!logStr.trim()) { return `No logs found for container '${id}'.`; } return `Logs for container '${id}' (last ${tail} lines):\n\n${logStr}`; } - src/tools/docker/index.ts:30-41 (registration)Tool registration for 'docker_container_logs' including input schema.
name: "docker_container_logs", description: "Fetch logs from a Docker container", inputSchema: { type: "object" as const, properties: { id: { type: "string", description: "Container ID or name" }, tail: { type: "number", description: "Number of lines from end (default: 100)" }, since: { type: "number", description: "Unix timestamp to start from" }, }, required: ["id"], }, },