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
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform on containers | |
| container | No | Container name or ID | |
| command | No | Command to execute (for exec action) | |
| follow | No | Follow log output (for logs action) | |
| tail | No | Number of lines to show from end of logs | |
| all | No | Show all containers including stopped ones | |
| force | No | Force operation | |
| volumes | No | Remove associated volumes (for remove action) |
Implementation Reference
- src/services/DockerService.ts:690-853 (handler)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); - src/toolDefinitions.ts:509-530 (registration)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'], }, },