docker_restart
Restart Docker containers by name or ID to apply configuration changes, resolve issues, or update running services. Specify timeout and working directory for controlled container restarts.
Instructions
Restart one or more containers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| containers | Yes | Container name(s) or ID(s) | |
| timeout | No | Seconds to wait before killing container | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/docker.ts:255-259 (handler)The core handler function that constructs and executes the 'docker restart' command using the shared executeDockerCommand helper, handling single or multiple containers with optional timeout.export async function dockerRestart(args: z.infer<typeof dockerRestartSchema>): Promise<ToolResponse> { const containers = Array.isArray(args.containers) ? args.containers.join(' ') : args.containers; const timeoutFlag = args.timeout ? `-t ${args.timeout}` : ''; return executeDockerCommand(`docker restart ${timeoutFlag} ${containers}`.trim(), args.cwd); }
- src/tools/docker.ts:125-129 (schema)Zod schema defining the input parameters for validation in the docker_restart tool handler.export const dockerRestartSchema = z.object({ containers: z.union([z.string(), z.array(z.string())]).describe('Container name(s) or ID(s)'), timeout: z.number().optional().describe('Seconds to wait before killing container'), cwd: z.string().optional().describe('Working directory') });
- src/index.ts:463-466 (registration)MCP server dispatch logic that handles 'docker_restart' tool calls by validating args with dockerRestartSchema and invoking the dockerRestart handler.if (name === 'docker_restart') { const validated = dockerRestartSchema.parse(args); return await dockerRestart(validated); }
- src/tools/docker.ts:447-465 (registration)Tool registration object in dockerTools array providing MCP-compatible name, description, and JSON inputSchema; included in server's listTools response.{ name: 'docker_restart', description: 'Restart one or more containers', inputSchema: { type: 'object', properties: { containers: { oneOf: [ { type: 'string' }, { type: 'array', items: { type: 'string' } } ], description: 'Container name(s) or ID(s)' }, timeout: { type: 'number', description: 'Seconds to wait before killing container' }, cwd: { type: 'string', description: 'Working directory' } }, required: ['containers'] } },
- src/tools/docker.ts:21-62 (helper)Shared helper function that executes Docker commands via child_process.execAsync, formats success/error responses in ToolResponse format, and handles timeouts/buffers.async function executeDockerCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024, // 10MB buffer for logs timeout: 60000 // 60 second timeout for builds }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }