container_exec
Execute commands in running Docker containers to manage processes, troubleshoot issues, or perform administrative tasks directly from the ChatGPT interface.
Instructions
Execute a command in a running container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | Yes | Container ID or name | |
| command | Yes | Command to execute |
Implementation Reference
- src/services/docker.service.ts:61-63 (handler)Core implementation of container_exec tool: executes `docker exec <container> <command>` via the generic executeCommand method.async execInContainer(id: string, command: string): Promise<string> { return this.executeCommand(`exec ${id} ${command}`); }
- src/servers/mcp.server.ts:287-296 (handler)Dispatch handler in MCP server for the 'container_exec' tool call, which parses arguments and invokes DockerService.execInContainer.case 'container_exec': { const { container, command } = request.params.arguments as { container: string; command: string; }; const output = await this.dockerService.execInContainer(container, command); return { content: [{ type: 'text', text: output }], }; }
- src/servers/mcp.server.ts:195-212 (schema)Input schema and metadata for the 'container_exec' tool, defining required parameters 'container' and 'command'.{ name: 'container_exec', description: 'Execute a command in a running container', inputSchema: { type: 'object', properties: { container: { type: 'string', description: 'Container ID or name', }, command: { type: 'string', description: 'Command to execute', }, }, required: ['container', 'command'], }, },
- src/services/docker.service.ts:8-18 (helper)Generic helper method used by execInContainer (and other tools) to run arbitrary 'docker <command>' via child_process.exec.async executeCommand(command: string): Promise<string> { try { const { stdout } = await execAsync(`docker ${command}`); return stdout; } catch (error: any) { throw new McpError( ErrorCode.InternalError, `Docker command failed: ${error.message}` ); } }