docker_networks
Performs Docker network actions: list, create, remove, inspect, connect, or disconnect containers to networks.
Instructions
Manage Docker networks
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform on networks | |
| network | No | Network name or ID | |
| container | No | Container to connect/disconnect | |
| driver | No | Network driver (bridge, overlay, host, etc.) | |
| subnet | No | Subnet for network (e.g., 172.20.0.0/16) | |
| gateway | No | Gateway for network |
Implementation Reference
- src/services/DockerService.ts:858-967 (handler)The manageNetworks method handles all network operations (list, create, remove, inspect, connect, disconnect, prune) by building and executing docker network CLI commands.
async manageNetworks(args: DockerNetworkArgs): Promise<ToolResult> { const { action, network, container, driver, gateway, subnet, ip_range, aux_address, opt, label, internal, attachable, ingress, ipv6, alias = [], ip, ip6, link = [], link_local_ip = [], force, filter } = args; ValidationUtils.validateRequired({ action }, ['action']); let command = 'docker network'; switch (action) { case 'list': command = 'docker network ls'; if (filter) command += ` --filter ${filter}`; break; case 'create': if (!network) throw new Error('Network name is required for create action'); command = `docker network create ${network}`; if (driver) command += ` --driver ${driver}`; if (gateway) command += ` --gateway ${gateway}`; if (subnet) command += ` --subnet ${subnet}`; if (ip_range) command += ` --ip-range ${ip_range}`; if (internal) command += ' --internal'; if (attachable) command += ' --attachable'; if (ingress) command += ' --ingress'; if (ipv6) command += ' --ipv6'; if (aux_address) { for (const [key, value] of Object.entries(aux_address)) { command += ` --aux-address ${key}=${value}`; } } if (opt) { for (const [key, value] of Object.entries(opt)) { command += ` --opt ${key}=${value}`; } } if (label) { for (const [key, value] of Object.entries(label)) { command += ` --label ${key}=${value}`; } } break; case 'remove': if (!network) throw new Error('Network name/ID is required for remove action'); command = `docker network rm ${network}`; break; case 'inspect': if (!network) throw new Error('Network name/ID is required for inspect action'); command = `docker network inspect ${network}`; break; case 'connect': if (!network || !container) throw new Error('Network and container are required for connect action'); command = `docker network connect`; alias.forEach(a => command += ` --alias ${a}`); if (ip) command += ` --ip ${ip}`; if (ip6) command += ` --ip6 ${ip6}`; link.forEach(l => command += ` --link ${l}`); link_local_ip.forEach(lip => command += ` --link-local-ip ${lip}`); command += ` ${network} ${container}`; break; case 'disconnect': if (!network || !container) throw new Error('Network and container are required for disconnect action'); command = `docker network disconnect`; if (force) command += ' -f'; command += ` ${network} ${container}`; break; case 'prune': command = 'docker network prune'; if (force) command += ' -f'; if (filter) command += ` --filter ${filter}`; break; default: throw new Error(`Unsupported network action: ${action}`); } try { return await this.executeDockerCommand(command, { cwd: this.getCurrentWorkspace() }); } catch (error: any) { throw new Error(`Docker network ${action} failed: ${error.message}`); } } - DockerNetworkArgs interface defines the input schema for network operations with action, network, container, driver, gateway, subnet, ip_range, aux_address, opt, label, internal, attachable, ingress, ipv6, alias, ip, ip6, link, link_local_ip, force, filter properties.
export interface DockerNetworkArgs { action: 'list' | 'create' | 'remove' | 'inspect' | 'connect' | 'disconnect' | 'prune'; network?: string; container?: string; driver?: string; gateway?: string; subnet?: string; ip_range?: string; aux_address?: Record<string, string>; opt?: Record<string, string>; label?: Record<string, string>; internal?: boolean; attachable?: boolean; ingress?: boolean; ipv6?: boolean; alias?: string[]; ip?: string; ip6?: string; link?: string[]; link_local_ip?: string[]; force?: boolean; filter?: string; } - src/index.ts:215-216 (registration)Dispatches the 'docker_networks' tool name to manageNetworks method on the DockerService.
case 'docker_networks': return await this.dockerService.manageNetworks(args as DockerNetworkArgs); - src/toolDefinitions.ts:531-550 (schema)TOOL_DEFINITIONS entry for 'docker_networks' with description and inputSchema (action, network, container, driver, subnet, gateway). Note: the schema in toolDefinitions is a subset of DockerNetworkArgs.
{ name: 'docker_networks', description: 'Manage Docker networks', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['list', 'create', 'remove', 'inspect', 'connect', 'disconnect'], description: 'Action to perform on networks' }, network: { type: 'string', description: 'Network name or ID' }, container: { type: 'string', description: 'Container to connect/disconnect' }, driver: { type: 'string', description: 'Network driver (bridge, overlay, host, etc.)' }, subnet: { type: 'string', description: 'Subnet for network (e.g., 172.20.0.0/16)' }, gateway: { type: 'string', description: 'Gateway for network' }, }, required: ['action'], }, },