
MCP Server for docker container creation and code execution
概览
A powerful Model Context Protocol (MCP) server that executes code in isolated Docker containers and returns the results to language models like Claude. - : Run code in Docker containers separated from your main system - : Execute code in any language with a Docker image - : Run both simple commands and complete multi-line scripts - : Install dependencies using pip, npm, apt-get, or apk - : Create, list, and clean up Docker containers easily - : Graceful timeout management and fallback mechanisms - : Clear, color-coded console feedback - Python 3.9+ - Docker installed and running - fastmcp library To test and explore the server's functionality: The MCP Inspector interface will open in your browser at http://localhost:5173. The Docker MCP server provides the following tools: Lists all Docker containers and their details: - : - show_all: (Optional) Whether to show all containers including stopped ones (default: True)
README
以下为原文 README 节选,完整内容请查看原文。
Docker MCP Server
A powerful Model Context Protocol (MCP) server that executes code in isolated Docker containers and returns the results to language models like Claude.
Features
- Isolated Code Execution: Run code in Docker containers separated from your main system
- Multi-language Support: Execute code in any language with a Docker image
- Complex Script Support: Run both simple commands and complete multi-line scripts
- Package Management: Install dependencies using pip, npm, apt-get, or apk
- Container Management: Create, list, and clean up Docker containers easily
- Robust Error Handling: Graceful timeout management and fallback mechanisms
- Colorful Output: Clear, color-coded console feedback
Requirements
- Python 3.9+
- Docker installed and running
- fastmcp library
Installation
-
Clone this repository:
git clone https://github.com/zaycruz/docker_mcp.git cd docker_mcp -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install required packages:
pip install -r requirements.txt
Usage
Running the MCP Inspector
To test and explore the server’s functionality:
python run_server.py
The MCP Inspector interface will open in your browser at http://localhost:5173.
Available Tools
The Docker MCP server provides the following tools:
1. List Containers
Lists all Docker containers and their details:
- Parameters:
show_all: (Optional) Whether to show all containers including stopped ones (default: True)
2. Create Container
Creates and starts a Docker container with optional dependencies:
- Parameters:
image: The Docker image to use (e.g., “python:3.9-slim”, “node:16”)container_name: A unique name for the containerdependencies: (Optional) Space-separated list of packages to install (e.g., “numpy pandas”, “express lodash”)
3. Add Dependencies
Installs additional packages in an existing Docker container:
- Parameters:
container_name: The name of the target containerdependencies: Space-separated list of packages to install
4. Execute Code
Executes a command inside a running Docker container:
- Parameters:
container_name: The name of the target containercommand: The command to execute inside the container
5. Execute Python Script
Executes a multi-line Python script inside a running Docker container:
- Parameters:
container_name: The name of the target containerscript_content: The full Python script contentscript_args: Optional arguments to pass to the script
6. Cleanup Container
Stops and removes a Docker container:
- Parameters:
container_name: The name of the container to clean up
Examples
Basic Workflow Example
# 1. List existing containers to see what's already running
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →