Skip to main content
Glama

docker_containers

List, start, stop, restart, remove, inspect, view logs, execute commands, and monitor resource usage of Docker containers.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on containers
containerNoContainer name or ID
commandNoCommand to execute (for exec action)
followNoFollow log output (for logs action)
tailNoNumber of lines to show from end of logs
allNoShow all containers including stopped ones
forceNoForce operation
volumesNoRemove associated volumes (for remove action)

Implementation Reference

  • The manageContainers method implements the core logic for the docker_containers tool. It handles all container actions (list, start, stop, restart, remove, inspect, logs, exec, stats, kill, pause, unpause, cp, export, rename, update, wait, prune) by constructing and executing docker CLI commands.
    async manageContainers(args: DockerContainerArgs): Promise<ToolResult> {
      const { 
        action, 
        container, 
        command: cmd, 
        interactive, 
        tty, 
        user, 
        workdir, 
        env = [], 
        follow, 
        tail, 
        since, 
        until, 
        timestamps, 
        details, 
        all, 
        filter, 
        force, 
        volumes, 
        signal, 
        time, 
        no_stream,
        source,
        destination,
        archive,
        new_name,
        memory,
        cpus,
        restart
      } = args;
    
      ValidationUtils.validateRequired({ action }, ['action']);
    
      let command = 'docker';
    
      switch (action) {
        case 'list':
          command = 'docker ps';
          if (all) command += ' -a';
          if (filter) command += ` --filter ${filter}`;
          break;
          
        case 'start':
          if (!container) throw new Error('Container name/ID is required for start action');
          command = `docker start ${container}`;
          break;
          
        case 'stop':
          if (!container) throw new Error('Container name/ID is required for stop action');
          command = `docker stop ${container}`;
          if (time) command += ` -t ${time}`;
          break;
          
        case 'restart':
          if (!container) throw new Error('Container name/ID is required for restart action');
          command = `docker restart ${container}`;
          if (time) command += ` -t ${time}`;
          break;
          
        case 'remove':
          if (!container) throw new Error('Container name/ID is required for remove action');
          command = `docker rm ${container}`;
          if (force) command += ' -f';
          if (volumes) command += ' -v';
          break;
          
        case 'inspect':
          if (!container) throw new Error('Container name/ID is required for inspect action');
          command = `docker inspect ${container}`;
          break;
          
        case 'logs':
          if (!container) throw new Error('Container name/ID is required for logs action');
          command = `docker logs ${container}`;
          if (follow) command += ' -f';
          if (tail) command += ` --tail ${tail}`;
          if (since) command += ` --since ${since}`;
          if (until) command += ` --until ${until}`;
          if (timestamps) command += ' -t';
          if (details) command += ' --details';
          break;
          
        case 'exec':
          if (!container || !cmd) throw new Error('Container name/ID and command are required for exec action');
          command = `docker exec`;
          if (interactive) command += ' -i';
          if (tty) command += ' -t';
          if (user) command += ` -u ${user}`;
          if (workdir) command += ` -w ${workdir}`;
          env.forEach(e => command += ` -e ${e}`);
          command += ` ${container} ${cmd}`;
          break;
          
        case 'stats':
          command = 'docker stats';
          if (container) command += ` ${container}`;
          if (all) command += ' -a';
          if (no_stream) command += ' --no-stream';
          break;
          
        case 'kill':
          if (!container) throw new Error('Container name/ID is required for kill action');
          command = `docker kill ${container}`;
          if (signal) command += ` -s ${signal}`;
          break;
          
        case 'pause':
          if (!container) throw new Error('Container name/ID is required for pause action');
          command = `docker pause ${container}`;
          break;
          
        case 'unpause':
          if (!container) throw new Error('Container name/ID is required for unpause action');
          command = `docker unpause ${container}`;
          break;
          
        case 'cp':
          if (!container || !source || !destination) {
            throw new Error('Container, source, and destination are required for cp action');
          }
          command = `docker cp ${source} ${container}:${destination}`;
          if (archive) command += ' -a';
          break;
          
        case 'export':
          if (!container) throw new Error('Container name/ID is required for export action');
          command = `docker export ${container}`;
          break;
          
        case 'rename':
          if (!container || !new_name) throw new Error('Container name/ID and new name are required for rename action');
          command = `docker rename ${container} ${new_name}`;
          break;
          
        case 'update':
          if (!container) throw new Error('Container name/ID is required for update action');
          command = `docker update ${container}`;
          if (memory) command += ` --memory ${memory}`;
          if (cpus) command += ` --cpus ${cpus}`;
          if (restart) command += ` --restart ${restart}`;
          break;
          
        case 'wait':
          if (!container) throw new Error('Container name/ID is required for wait action');
          command = `docker wait ${container}`;
          break;
          
        case 'prune':
          command = 'docker container prune';
          if (force) command += ' -f';
          if (filter) command += ` --filter ${filter}`;
          break;
          
        default:
          throw new Error(`Unsupported container action: ${action}`);
      }
    
      try {
        return await this.executeDockerCommand(command, { cwd: this.getCurrentWorkspace() });
      } catch (error: any) {
        throw new Error(`Docker container ${action} failed: ${error.message}`);
      }
    }
  • The DockerContainerArgs interface defines the input schema for the docker_containers tool, including all supported actions and options (action, container, command, interactive, tty, user, workdir, env, follow, tail, since, until, timestamps, details, all, filter, force, volumes, signal, time, no_stream, source, destination, archive, new_name, memory, cpus, restart).
    export interface DockerContainerArgs {
      action: 'list' | 'start' | 'stop' | 'restart' | 'remove' | 'inspect' | 'logs' | 'exec' | 'stats' | 'kill' | 'pause' | 'unpause' | 'attach' | 'cp' | 'export' | 'port' | 'rename' | 'update' | 'wait' | 'prune';
      container?: string;
      command?: string;
      interactive?: boolean;
      tty?: boolean;
      user?: string;
      workdir?: string;
      env?: string[];
      follow?: boolean;
      tail?: number;
      since?: string;
      until?: string;
      timestamps?: boolean;
      details?: boolean;
      all?: boolean;
      filter?: string;
      force?: boolean;
      volumes?: boolean;
      signal?: string;
      time?: number;
      no_stream?: boolean;
      source?: string;
      destination?: string;
      archive?: boolean;
      new_name?: string;
      memory?: string;
      cpus?: string;
      restart?: string;
    }
  • src/index.ts:213-214 (registration)
    Registration in the tool dispatcher: the 'docker_containers' case routes to dockerService.manageContainers(args).
    case 'docker_containers':
      return await this.dockerService.manageContainers(args as DockerContainerArgs);
  • Tool definition registration with name 'docker_containers', description, and inputSchema listing the properties and allowed enum values for the action field.
    {
      name: 'docker_containers',
      description: 'Manage Docker containers (list, start, stop, remove, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          action: { 
            type: 'string', 
            enum: ['list', 'start', 'stop', 'restart', 'remove', 'inspect', 'logs', 'exec', 'stats'],
            description: 'Action to perform on containers' 
          },
          container: { type: 'string', description: 'Container name or ID' },
          command: { type: 'string', description: 'Command to execute (for exec action)' },
          follow: { type: 'boolean', description: 'Follow log output (for logs action)' },
          tail: { type: 'number', description: 'Number of lines to show from end of logs' },
          all: { type: 'boolean', description: 'Show all containers including stopped ones' },
          force: { type: 'boolean', description: 'Force operation' },
          volumes: { type: 'boolean', description: 'Remove associated volumes (for remove action)' },
        },
        required: ['action'],
      },
    },
Behavior3/5

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

No annotations are provided, so the description must disclose behavioral traits. It implies destructive actions (stop, remove) but does not explain side effects, permissions, or outcomes. The schema lists actions, but the description adds little beyond the action names.

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

Conciseness4/5

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

The description is a single sentence that is concise and front-loaded. It includes key actions but ends with 'etc.', which is acceptable for brevity.

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

Completeness3/5

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

Given 8 parameters and no output schema, the description is minimal. While the schema provides parameter details, the description lacks context on return values or behavior for each action, which is important for a multi-action tool.

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?

All parameters are described in the schema with 100% coverage. The description adds nothing beyond listing action examples (list, start, stop, remove) which are already in the schema enum. Baseline score of 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 and lists example actions (list, start, stop, remove). However, it does not differentiate from sibling tools like docker_run or docker_cleanup, which also deal with containers.

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 guidance is provided on when to use this tool versus sibling tools like docker_run or docker_cleanup. It lacks context for choosing the right tool.

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/agentics-ai/code-mcp'

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