Skip to main content
Glama

manage_containers

Perform actions on Docker containers including listing, starting, stopping, removing, and restarting them to manage container lifecycle.

Instructions

Manage Docker containers (list, start, stop, remove)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on containers
containerNoContainer name or ID (required for start, stop, remove, restart)
allNoInclude stopped containers when listing

Implementation Reference

  • Handler function that takes action (list/start/stop/remove/restart), container name, and all flag, constructs the appropriate docker command, executes it via executeDockerCommand, and returns the result or error.
    async ({ action, container, all }) => { try { let command: string; switch (action) { case "list": command = all ? "docker ps -a" : "docker ps"; break; case "start": if (!container) throw new Error("Container name or ID is required for start action"); command = `docker start ${container}`; break; case "stop": if (!container) throw new Error("Container name or ID is required for stop action"); command = `docker stop ${container}`; break; case "remove": if (!container) throw new Error("Container name or ID is required for remove action"); command = `docker rm ${container}`; break; case "restart": if (!container) throw new Error("Container name or ID is required for restart action"); command = `docker restart ${container}`; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Container ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing containers: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • Zod input schema defining the parameters for the manage_containers tool: action enum, optional container string, optional all boolean.
    inputSchema: { action: z.enum(["list", "start", "stop", "remove", "restart"]).describe("Action to perform on containers"), container: z.string().optional().describe("Container name or ID (required for start, stop, remove, restart)"), all: z.boolean().optional().describe("Include stopped containers when listing") }
  • src/index.ts:1198-1257 (registration)
    Registration of the manage_containers tool with McpServer using server.registerTool, including title, description, inputSchema, and handler function.
    server.registerTool( "manage_containers", { title: "Manage Docker Containers", description: "Manage Docker containers (list, start, stop, remove)", inputSchema: { action: z.enum(["list", "start", "stop", "remove", "restart"]).describe("Action to perform on containers"), container: z.string().optional().describe("Container name or ID (required for start, stop, remove, restart)"), all: z.boolean().optional().describe("Include stopped containers when listing") } }, async ({ action, container, all }) => { try { let command: string; switch (action) { case "list": command = all ? "docker ps -a" : "docker ps"; break; case "start": if (!container) throw new Error("Container name or ID is required for start action"); command = `docker start ${container}`; break; case "stop": if (!container) throw new Error("Container name or ID is required for stop action"); command = `docker stop ${container}`; break; case "remove": if (!container) throw new Error("Container name or ID is required for remove action"); command = `docker rm ${container}`; break; case "restart": if (!container) throw new Error("Container name or ID is required for restart action"); command = `docker restart ${container}`; break; } const result = await executeDockerCommand(command); return { content: [ { type: "text", text: `Container ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error managing containers: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
  • Helper function used by the handler to execute Docker commands asynchronously using child_process exec.
    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