Skip to main content
Glama

remove_container

Delete a Docker container by ID or name. Use the force option to remove running containers.

Instructions

Remove a Docker container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer ID or name
forceNoForce removal of running container

Implementation Reference

  • The main handler function for the 'remove_container' tool. It validates the container argument, constructs the 'docker rm' command with optional force flag, executes it, and returns the stdout.
    private async removeContainer(args: ContainerActionArgs) {
      if (!args.container) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Container parameter is required'
        );
      }
      
      const force = args.force === true ? ' -f' : '';
      const { stdout } = await execAsync(`docker rm${force} ${args.container}`);
      
      return {
        content: [
          {
            type: 'text',
            text: stdout.trim(),
          },
        ],
      };
    }
  • TypeScript interface defining the input parameters for remove_container and similar container actions.
    interface ContainerActionArgs {
      container: string;
      force?: boolean;
    }
  • src/index.ts:151-168 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      name: 'remove_container',
      description: 'Remove a Docker container',
      inputSchema: {
        type: 'object',
        properties: {
          container: {
            type: 'string',
            description: 'Container ID or name',
          },
          force: {
            type: 'boolean',
            description: 'Force removal of running container',
          },
        },
        required: ['container'],
      },
    },
  • Switch case in the CallToolRequest handler that dispatches to the removeContainer method.
    case 'remove_container':
      return await this.removeContainer(request.params.arguments as unknown as ContainerActionArgs);

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/suvarchal/docker-mcp'

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