Skip to main content
Glama

manage_images

Perform Docker image operations including listing available images, pulling from registries, removing unused images, and building new images from Dockerfiles.

Instructions

Manage Docker images (list, pull, remove, build)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on images
dockerfileNoPath to Dockerfile (required for build)
imageNoImage name or ID (required for pull, remove, build)
tagNoTag for the image (optional for pull, required for build)

Implementation Reference

  • src/index.ts:1259-1318 (registration)
    Registration of the 'manage_images' MCP tool, including title, description, input schema, and handler function reference.
    // Register Docker image management tool server.registerTool( "manage_images", { title: "Manage Docker Images", description: "Manage Docker images (list, pull, remove, build)", inputSchema: { action: z.enum(["list", "pull", "remove", "build"]).describe("Action to perform on images"), image: z.string().optional().describe("Image name or ID (required for pull, remove, build)"), tag: z.string().optional().describe("Tag for the image (optional for pull, required for build)"), dockerfile: z.string().optional().describe("Path to Dockerfile (required for build)") } }, async ({ action, image, tag, dockerfile }) => { try { let command: string; switch (action) { case "list": command = "docker images"; break; case "pull": if (!image) throw new Error("Image name is required for pull action"); command = tag ? `docker pull ${image}:${tag}` : `docker pull ${image}`; break; case "remove": if (!image) throw new Error("Image name or ID is required for remove action"); command = `docker rmi ${image}`; break; case "build": if (!image) throw new Error("Image name is required for build action"); const buildTag = tag ? `${image}:${tag}` : image; const context = dockerfile ? dockerfile : "."; command = `docker build -t ${buildTag} ${context}`; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Image ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing images: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
  • The handler function implements the core logic for the 'manage_images' tool. It constructs and executes appropriate Docker commands based on the 'action' parameter (list, pull, remove, or build), using the provided image, tag, and dockerfile parameters. It leverages the executeDockerCommand helper and returns formatted results or error responses.
    async ({ action, image, tag, dockerfile }) => { try { let command: string; switch (action) { case "list": command = "docker images"; break; case "pull": if (!image) throw new Error("Image name is required for pull action"); command = tag ? `docker pull ${image}:${tag}` : `docker pull ${image}`; break; case "remove": if (!image) throw new Error("Image name or ID is required for remove action"); command = `docker rmi ${image}`; break; case "build": if (!image) throw new Error("Image name is required for build action"); const buildTag = tag ? `${image}:${tag}` : image; const context = dockerfile ? dockerfile : "."; command = `docker build -t ${buildTag} ${context}`; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Image ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing images: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • Zod-based input schema for the 'manage_images' tool, defining validation for action (enum: list/pull/remove/build), optional image name/ID, tag, and dockerfile path with descriptions.
    inputSchema: { action: z.enum(["list", "pull", "remove", "build"]).describe("Action to perform on images"), image: z.string().optional().describe("Image name or ID (required for pull, remove, build)"), tag: z.string().optional().describe("Tag for the image (optional for pull, required for build)"), dockerfile: z.string().optional().describe("Path to Dockerfile (required for build)") }
  • Helper function 'executeDockerCommand' used by the manage_images handler (and other tools) to execute Docker CLI commands asynchronously via child_process.exec, returning stdout/stderr or throwing errors.
    async function executeDockerCommand(command: string): Promise<{ stdout: string; stderr: string }> { try { const result = await execAsync(command); return result; } catch (error: any) { throw new Error(`Docker command failed: ${error.message}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TauqeerAhmad5201/docker-mcp-extension'

If you have feedback or need assistance with the MCP directory API, please join our Discord server