docker_compose_down
Stop and remove Docker containers and networks created by docker-compose up, with options to delete volumes and orphaned containers for clean environment management.
Instructions
Stop and remove containers, networks created by docker-compose up
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| volumes | No | Remove named volumes | |
| removeOrphans | No | Remove containers for services not in compose file | |
| file | No | Path to compose file | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/docker.ts:309-319 (handler)The main handler function that constructs and executes the 'docker compose down' command with options for volumes, orphans, compose file, and working directory.export async function dockerComposeDown(args: z.infer<typeof dockerComposeDownSchema>): Promise<ToolResponse> { const volumesFlag = args.volumes ? '-v' : ''; const orphansFlag = args.removeOrphans ? '--remove-orphans' : ''; const fileFlag = args.file ? `-f ${args.file}` : ''; const composeCmd = await getComposeCmd(); return executeDockerCommand( `${composeCmd} ${fileFlag} down ${volumesFlag} ${orphansFlag}`.trim(), args.cwd ); }
- src/tools/docker.ts:168-173 (schema)Zod schema used for runtime input validation of the docker_compose_down tool parameters.export const dockerComposeDownSchema = z.object({ volumes: z.boolean().optional().default(false).describe('Remove named volumes'), removeOrphans: z.boolean().optional().default(false).describe('Remove containers for services not in compose file'), file: z.string().optional().describe('Path to compose file'), cwd: z.string().optional().describe('Working directory') });
- src/tools/docker.ts:536-548 (registration)MCP tool definition/registration in the dockerTools array, including JSON schema for tool listing.{ name: 'docker_compose_down', description: 'Stop and remove containers, networks created by docker-compose up', inputSchema: { type: 'object', properties: { volumes: { type: 'boolean', default: false, description: 'Remove named volumes' }, removeOrphans: { type: 'boolean', default: false, description: 'Remove containers for services not in compose file' }, file: { type: 'string', description: 'Path to compose file' }, cwd: { type: 'string', description: 'Working directory' } } } },
- src/index.ts:487-489 (registration)Runtime dispatch/registration in the main CallToolRequest handler that routes calls to the dockerComposeDown function after schema validation.if (name === 'docker_compose_down') { const validated = dockerComposeDownSchema.parse(args); return await dockerComposeDown(validated);
- src/tools/docker.ts:21-62 (helper)Core helper function used by all Docker tools, including dockerComposeDown, to execute shell commands and format responses.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 }; } }