docker_compose_up
Start and run Docker containers from your docker-compose.yml file to launch development environments and services with options for background operation, selective services, and custom compose files.
Instructions
Create and start containers defined in docker-compose.yml
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| detach | No | Detached mode: run in background | |
| build | No | Build images before starting | |
| services | No | Only start specific services | |
| file | No | Path to compose file (default: docker-compose.yml) | |
| cwd | No | Working directory (where docker-compose.yml is located) |
Implementation Reference
- src/tools/docker.ts:296-307 (handler)The core handler function that constructs and executes the 'docker compose up' command using dynamic flags based on input arguments and the executeDockerCommand helper.export async function dockerComposeUp(args: z.infer<typeof dockerComposeUpSchema>): Promise<ToolResponse> { const detachFlag = args.detach ? '-d' : ''; const buildFlag = args.build ? '--build' : ''; const services = args.services ? args.services.join(' ') : ''; const fileFlag = args.file ? `-f ${args.file}` : ''; const composeCmd = await getComposeCmd(); return executeDockerCommand( `${composeCmd} ${fileFlag} up ${detachFlag} ${buildFlag} ${services}`.trim(), args.cwd ); }
- src/tools/docker.ts:160-166 (schema)Zod schema defining the input validation for the docker_compose_up tool parameters.export const dockerComposeUpSchema = z.object({ detach: z.boolean().optional().default(true).describe('Detached mode: run in background'), build: z.boolean().optional().default(false).describe('Build images before starting'), services: z.array(z.string()).optional().describe('Only start specific services'), file: z.string().optional().describe('Path to compose file (default: docker-compose.yml)'), cwd: z.string().optional().describe('Working directory (where docker-compose.yml is located)') });
- src/tools/docker.ts:522-535 (registration)Tool registration entry in the dockerTools array, providing the MCP-compatible tool definition with name, description, and JSON input schema.{ name: 'docker_compose_up', description: 'Create and start containers defined in docker-compose.yml', inputSchema: { type: 'object', properties: { detach: { type: 'boolean', default: true, description: 'Detached mode: run in background' }, build: { type: 'boolean', default: false, description: 'Build images before starting' }, services: { type: 'array', items: { type: 'string' }, description: 'Only start specific services' }, file: { type: 'string', description: 'Path to compose file (default: docker-compose.yml)' }, cwd: { type: 'string', description: 'Working directory (where docker-compose.yml is located)' } } } },
- src/index.ts:483-486 (registration)Dynamic tool dispatch handler in the main MCP server that routes calls to 'docker_compose_up' by validating arguments with the schema and invoking the handler function.if (name === 'docker_compose_up') { const validated = dockerComposeUpSchema.parse(args); return await dockerComposeUp(validated); }
- src/tools/docker.ts:21-62 (helper)Core helper function that executes shell commands (used by dockerComposeUp) and formats output as ToolResponse with success/error handling.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 }; } }