docker_rmi
Remove Docker images from your system by name or ID to free up disk space and manage container resources during development workflows.
Instructions
Remove one or more images
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| images | Yes | Image name(s) or ID(s) to remove | |
| force | No | Force removal | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/docker.ts:355-360 (handler)Main handler function that executes 'docker rmi' command with optional force flag and cwd.export async function dockerRmi(args: z.infer<typeof dockerRmiSchema>): Promise<ToolResponse> { const images = Array.isArray(args.images) ? args.images.join(' ') : args.images; const forceFlag = args.force ? '-f' : ''; return executeDockerCommand(`docker rmi ${forceFlag} ${images}`.trim(), args.cwd); }
- src/tools/docker.ts:198-202 (schema)Zod schema defining input parameters for the docker_rmi tool: images (string or array), force (boolean), cwd (string).export const dockerRmiSchema = z.object({ images: z.union([z.string(), z.array(z.string())]).describe('Image name(s) or ID(s) to remove'), force: z.boolean().optional().default(false).describe('Force removal'), cwd: z.string().optional().describe('Working directory') });
- src/tools/docker.ts:597-615 (registration)MCP tool definition/registration for 'docker_rmi' in the exported dockerTools array, including JSON schema.{ name: 'docker_rmi', description: 'Remove one or more images', inputSchema: { type: 'object', properties: { images: { oneOf: [ { type: 'string' }, { type: 'array', items: { type: 'string' } } ], description: 'Image name(s) or ID(s) to remove' }, force: { type: 'boolean', default: false, description: 'Force removal' }, cwd: { type: 'string', description: 'Working directory' } }, required: ['images'] } }
- src/index.ts:503-506 (handler)Dispatcher in main MCP server CallToolRequest handler that validates arguments with dockerRmiSchema and calls dockerRmi function.if (name === 'docker_rmi') { const validated = dockerRmiSchema.parse(args); return await dockerRmi(validated); }
- src/tools/docker.ts:21-62 (helper)Shared helper function used by all Docker tools to execute docker commands via child_process.exec with proper error handling and JSON output formatting.async function executeDockerCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024, // 10MB buffer for logs timeout: 60000 // 60 second timeout for builds }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }