Skip to main content
Glama

Manage Docker Containers

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}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but provides minimal behavioral context. It mentions actions but doesn't disclose permissions needed, side effects (e.g., data loss on remove), or error conditions. For a tool with destructive operations, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely concise single sentence with zero wasted words. Front-loaded with the core purpose, though it could be more complete by including 'restart' from the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with multiple potentially destructive actions (stop, remove, restart), no annotations, and no output schema, the description is insufficient. It doesn't explain return values, error handling, or safety considerations, leaving significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters. The description adds no additional meaning about parameters beyond implying the tool handles multiple actions, which is already clear from the schema's enum. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool manages Docker containers with specific verbs (list, start, stop, remove), though it omits 'restart' which appears in the schema. It distinguishes from siblings like create_container and manage_images by focusing on lifecycle operations rather than creation or image management.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives like docker_compose or execute_docker_command. The description lists actions but doesn't provide context for choosing between this multi-action tool and more specialized siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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