Skip to main content
Glama
zaycruz

Docker MCP Server

by zaycruz

Docker MCP 服务器

强大的模型上下文协议 (MCP) 服务器,在隔离的 Docker 容器中执行代码并将结果返回给 Claude 等语言模型。

特征

  • 隔离代码执行:在与主系统分离的 Docker 容器中运行代码

  • 多语言支持:使用 Docker 镜像以任何语言执行代码

  • 复杂脚本支持:运行简单命令和完整的多行脚本

  • 软件包管理:使用 pip、npm、apt-get 或 apk 安装依赖项

  • 容器管理:轻松创建、列出和清理 Docker 容器

  • 强大的错误处理:优雅的超时管理和回退机制

  • 彩色输出:清晰、彩色编码的控制台反馈

Related MCP server: Isolator MCP Server

要求

  • Python 3.9+

  • Docker 安装并运行

  • fastmcp 库

安装

  1. 克隆此存储库:

    git clone https://github.com/yourusername/docker_mcp_server.git
    cd docker_mcp_server
  2. 创建虚拟环境:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. 安装所需的软件包:

    pip install -r requirements.txt

用法

运行 MCP 检查器

要测试和探索服务器的功能:

python run_server.py

MCP Inspector 界面将在您的浏览器中打开,网址为http://localhost:5173

可用工具

Docker MCP 服务器提供以下工具:

1. 列出容器

列出所有 Docker 容器及其详细信息:

  • 参数

    • show_all :(可选)是否显示所有容器(包括已停止的容器)(默认值:True)

2.创建容器

创建并启动具有可选依赖项的 Docker 容器:

  • 参数

    • image :要使用的 Docker 镜像(例如“python:3.9-slim”、“node:16”)

    • container_name :容器的唯一名称

    • dependencies :(可选)要安装的软件包的空格分隔列表(例如,“numpy pandas”,“express lodash”)

3.添加依赖项

在现有的 Docker 容器中安装其他软件包:

  • 参数

    • container_name :目标容器的名称

    • dependencies :要安装的软件包的空格分隔列表

4.执行代码

在正在运行的 Docker 容器内执行命令:

  • 参数

    • container_name :目标容器的名称

    • command :容器内执行的命令

5.执行Python脚本

在正在运行的 Docker 容器内执行多行 Python 脚本:

  • 参数

    • container_name :目标容器的名称

    • script_content :完整的 Python 脚本内容

    • script_args :传递给脚本的可选参数

6.清理容器

停止并删除 Docker 容器:

  • 参数

    • container_name :要清理的容器的名称

示例

基本工作流程示例

# 1. List existing containers to see what's already running
list_containers()

# 2. Create a new container
create_container(
    image="python:3.9-slim", 
    container_name="python-example", 
    dependencies="numpy pandas"
)

# 3. Execute a command in the container
execute_code(
    container_name="python-example", 
    command="python -c 'import numpy as np; print(\"NumPy version:\", np.__version__)'"
)

# 4. Add more dependencies later
add_dependencies(
    container_name="python-example", 
    dependencies="matplotlib scikit-learn"
)

# 5. List containers again to confirm status
list_containers(show_all=False)  # Only show running containers

# 6. Clean up when done
cleanup_container(container_name="python-example")

Python数据分析示例

# 1. Create a container with dependencies
create_container(
    image="python:3.9-slim", 
    container_name="python-test", 
    dependencies="numpy pandas matplotlib"
)

# 2. Execute a Python script
script = """
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Create some data
data = pd.DataFrame({
    'x': np.random.randn(100),
    'y': np.random.randn(100)
})

print(f"Data shape: {data.shape}")
print(f"Data correlation: {data.corr().iloc[0,1]:.4f}")
"""
execute_python_script(container_name="python-test", script_content=script)

# 3. Add additional dependencies later if needed
add_dependencies(container_name="python-test", dependencies="scikit-learn")

# 4. Verify container is running
list_containers(show_all=False)

# 5. Clean up when done
cleanup_container(container_name="python-test")

Node.js 示例

# 1. Check for existing Node.js containers
list_containers()

# 2. Create a Node.js container
create_container(
    image="node:16", 
    container_name="node-test", 
    dependencies="express axios"
)

# 3. Execute a Node.js script
execute_code(
    container_name="node-test", 
    command="node -e \"console.log('Node.js version: ' + process.version); console.log('Express installed: ' + require.resolve('express'));\""
)

# 4. Add more dependencies
add_dependencies(container_name="node-test", dependencies="lodash moment")

# 5. Clean up when done
cleanup_container(container_name="node-test")

包管理器支持

Docker MCP 服务器会自动检测并使用适当的包管理器:

  • Python 容器:使用pip

  • Node.js 容器:使用npm

  • Debian/Ubuntu 容器:使用apt-get

  • Alpine 容器:使用apk

对于从图像名称中无法明显看出包管理器的容器,服务器会尝试检测可用的包管理器。

与 Claude 及其他法学硕士课程的整合

此 MCP 服务器可以与 Claude 以及其他支持模型上下文协议 (MCP) 的 LLM 集成。使用fastmcp install命令将其注册到 Claude:

fastmcp install src/docker_mcp.py

故障排除

  • 端口已在使用中:如果您看到“地址已在使用中”错误,请确保没有其他 MCP Inspector 实例正在运行。

  • Docker 连接问题:使用docker --version验证 Docker 是否正在运行。

  • 容器超时:服务器包含针对未在预期时间范围内响应的容器的回退机制。

  • 软件包安装失败:检查指定软件包管理器的软件包名称是否正确。

  • 未找到容器:如果 list_containers 没有显示结果,Docker 可能尚未创建任何容器。

安全注意事项

此服务器在 Docker 容器中执行代码,从而与主机系统隔离。但是,请谨慎操作:

  • 在没有采取额外安全措施的情况下,请勿公开此服务器

  • 将主机卷安装到容器中时要小心

  • 考虑容器的资源限制以防止 DoS 攻击

执照

MIT 许可证

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

A
license - permissive license
Not graded
quality - not tested
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides isolated Docker environments for code execution, enabling users to create and manage containers, execute multi-language code, save and reproduce development environments, ensuring security and isolation.
    17
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants like Claude to manage Docker containers, images, and Docker Compose deployments through the Model Context Protocol. Provides secure container lifecycle management, image operations, and multi-host Docker server connections.
    194
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLMs to safely execute code in isolated Docker containers with resource limits and security controls, supporting session management and automatic dependency installation.
    MIT

View all related MCP servers

Related MCP Connectors

  • Execute code in 8 languages (Python, JS, TS, Go, Java, C++, C, Bash) in gVisor sandboxes.

  • Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.

  • A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zaycruz/docker_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server