Skip to main content
Glama
zaycruz

Docker MCP Server

by zaycruz

Docker MCP サーバー

分離された Docker コンテナ内でコードを実行し、その結果を Claude などの言語モデルに返す強力なモデル コンテキスト プロトコル (MCP) サーバー。

特徴

  • 分離されたコード実行: メインシステムから分離された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使用

  • アルパインコンテナapkを使用

イメージ名からパッケージ マネージャーが明らかでないコンテナーの場合、サーバーは利用可能なパッケージ マネージャーを検出しようとします。

クロードと他のLLMとの統合

このMCPサーバーは、Claudeやモデルコンテキストプロトコルをサポートする他のLLMと統合できます。Claudeに登録するには、 fastmcp installコマンドを使用してください。

fastmcp install src/docker_mcp.py

トラブルシューティング

  • ポートは既に使用されています: 「アドレスは既に使用されています」というエラーが表示される場合は、他の MCP Inspector インスタンスが実行されていないことを確認してください。

  • Docker 接続の問題: docker --versionを使用して Docker が実行されていることを確認します。

  • コンテナのタイムアウト: サーバーには、予期された時間内に応答しないコンテナのためのフォールバック メカニズムが含まれています。

  • パッケージのインストール失敗: 指定されたパッケージ マネージャーのパッケージ名が正しいことを確認してください。

  • コンテナーが見つかりません: list_containers に結果が表示されない場合は、Docker にまだコンテナーが作成されていない可能性があります。

セキュリティに関する考慮事項

このサーバーはDockerコンテナ内でコードを実行するため、ホストシステムから分離されます。ただし、以下の点にご注意ください。

  • 追加のセキュリティ対策を講じずにこのサーバーを公開しないでください

  • ホストボリュームをコンテナにマウントするときは注意してください

  • DoS攻撃を防ぐためにコンテナのリソース制限を検討する

ライセンス

MITライセンス

貢献

貢献を歓迎します!お気軽にプルリクエストを送信してください。

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