gnosis-docker-mcp

gnosis-docker-mcp

Enables AI assistants to manage Docker containers and images, including starting, stopping, listing, and building operations.

Category
访问服务器

README

Gnosis Docker

A Flask async server that exposes Docker management endpoints for MCP (Model Context Protocol) integration with Claude Desktop and Claude Code. This server communicates with the Docker daemon via Docker socket mounting, enabling comprehensive container management through AI assistants.

Features

  • Full Docker container management (list, start, stop, restart, remove)
  • Docker image management (list, pull, remove, build)
  • Container logs streaming and stats monitoring
  • Container inspection and health checks
  • Docker build triggers for Gnosis projects
  • Async Flask server with proper error handling
  • Security middleware for local-only access
  • MCP tools for AI assistant integration

Prerequisites and Setup

Windows with WSL2 (Recommended)

Gnosis Docker works best on Windows using WSL2 with Docker Desktop, as it provides native Docker socket access:

1. Install WSL2

# Run as Administrator in PowerShell
wsl --install
# Restart your computer

2. Install Docker Desktop

  • Download Docker Desktop from https://www.docker.com/products/docker-desktop/
  • During installation, ensure "Use WSL 2 based engine" is selected
  • Start Docker Desktop

3. Configure Docker Desktop for WSL2

# Run the setup helper script
.\setup-docker-desktop.ps1

Or manually configure:

  1. Open Docker Desktop Settings
  2. Go to General tab → Enable "Use WSL 2 based engine"
  3. Go to ResourcesWSL Integration → Enable integration with your WSL2 distro
  4. Optional for development: In General tab → Enable "Expose daemon on tcp://localhost:2375 without TLS"
  5. Click Apply & Restart

4. Verify Docker Socket Access

In WSL2:

# Check if Docker socket is accessible
ls -la /var/run/docker.sock
# Should show: srw-rw---- 1 root docker 0 [date] /var/run/docker.sock

# Test Docker connection
docker version

Windows without WSL2 (Limited)

For development without WSL2, you can use Docker Desktop's TCP endpoint:

  1. Enable TCP endpoint in Docker Desktop (Settings → General → "Expose daemon on tcp://localhost:2375")
  2. Set environment variable: $env:DOCKER_HOST = "tcp://localhost:2375"
  3. Run: .\setup-docker-desktop.ps1 to verify setup

Note: This method has limitations and security considerations. WSL2 is strongly recommended.

Docker Socket Communication

Gnosis Docker uses Docker socket mounting to communicate with the Docker daemon:

  • WSL2: Uses Unix socket /var/run/docker.sock (mounted into containers)
  • TCP: Uses tcp://localhost:2375 (for development only)
  • Security: The server validates all container operations and mounts

Directory Structure

gnosis-docker/
├── deploy.ps1              # Single deployment script for all environments
├── deploy-wsl2.sh          # WSL2 deployment script
├── requirements.txt        # Python dependencies
├── setup.ps1               # Initial setup script
├── setup-docker-desktop.ps1 # Docker Desktop configuration helper
├── Dockerfile             # Docker configuration
├── docker-compose.yml     # Local development with Redis
├── .env.example           # Environment variable template
├── .gitignore            # Git ignore file
├── README.md             # This file
├── WSL2_README.md        # WSL2-specific documentation
├── app.py                # Main Flask application
├── core/                 # Core application modules
│   ├── __init__.py
│   ├── docker_manager.py  # Docker operations handler
│   ├── auth.py           # Authentication middleware
│   ├── config.py         # Configuration management
│   ├── validation.py     # Container security validation
│   └── utils.py          # Utility functions
├── tests/                # Test suite
│   ├── __init__.py
│   └── test_docker_api.py
├── mcp/                  # MCP Tools Directory
│   ├── README.md         # MCP tools documentation
│   ├── requirements.txt  # MCP-specific dependencies
│   ├── setup.py          # MCP tools setup script
│   ├── gnosis_docker_mcp.py    # Docker management MCP tool
│   ├── file_manager_mcp.py     # File operations MCP tool
│   └── example_utilities_mcp.py # Example MCP tool
└── cleanup_*.py|ps1|sh   # Repository cleanup scripts

Quick Start

Deploy the Docker API Server

Windows WSL2 (Recommended)

# From WSL2 terminal
cd /mnt/c/Users/kord/Code/gnosis/gnosis-docker

# Make scripts executable
chmod +x deploy-wsl2.sh

# Deploy locally
./deploy-wsl2.sh

Windows PowerShell

# Initial setup (run once)
.\setup.ps1

# Windows - Deploy locally
.\deploy.ps1 -Target local

# Windows - Deploy to staging
.\deploy.ps1 -Target staging

# Windows - Deploy to production
.\deploy.ps1 -Target production

# Windows - Rebuild from scratch
.\deploy.ps1 -Target local -Rebuild

# Windows - Dry run (see what would happen)
.\deploy.ps1 -Target production -WhatIf

Use MCP Tools with AI Assistants

The /mcp directory contains ready-to-use MCP tools that integrate with Claude Code and Claude Desktop:

# Navigate to MCP tools
cd mcp

# Install dependencies
pip install -r requirements.txt

# Run setup and validation
python setup.py

# Configure with Claude Code
claude mcp add gnosis-docker python3 gnosis_docker_mcp.py

# Test the integration
claude
# Then try: "list docker containers", "check docker health"

See mcp/README.md for complete MCP setup instructions.

API Endpoints

Container Management

  • GET /health - Health check
  • GET /api/containers - List all containers
  • GET /api/containers/<id> - Get container details
  • POST /api/containers/<id>/start - Start container
  • POST /api/containers/<id>/stop - Stop container
  • POST /api/containers/<id>/restart - Restart container
  • DELETE /api/containers/<id> - Remove container
  • GET /api/containers/<id>/logs - Get container logs
  • GET /api/containers/<id>/stats - Get container stats

Image Management

  • GET /api/images - List all images
  • POST /api/images/pull - Pull an image
  • DELETE /api/images/<id> - Remove an image

Project Operations

  • POST /api/build - Build a Gnosis project
  • POST /api/projects/<name>/deploy - Deploy a project

MCP Integration

This server provides Docker management capabilities to AI assistants through MCP tools:

Available MCP Tools

  1. Gnosis Docker MCP (mcp/gnosis_docker_mcp.py)

    • Complete Docker management through Claude Code/Desktop
    • List, start, stop, restart containers
    • Get container logs and statistics
    • Manage Docker images
    • Build and deploy Gnosis projects
  2. File Manager MCP (mcp/file_manager_mcp.py)

    • Cross-platform file operations
    • Create, copy, move, delete files and directories
    • Backup support for safe operations
  3. Example Utilities MCP (mcp/example_utilities_mcp.py)

    • Demonstrates MCP development patterns
    • Basic utilities (echo, timestamps, calculations)
    • Text analysis and system information

Configuration Methods

Claude Code (Recommended):

claude mcp add gnosis-docker python3 /path/to/gnosis-docker/mcp/gnosis_docker_mcp.py

Claude Desktop: Add to claude_desktop_config.json:

{
  "mcpServers": {
    "gnosis-docker-mcp": {
      "command": "python",
      "args": ["C:\\path\\to\\gnosis-docker\\mcp\\gnosis_docker_mcp.py"]
    }
  }
}

Repository Maintenance

Clean Up Versioning Directories

This repository includes cleanup scripts to remove unwanted versioning directories and Python cache files:

# Python script (cross-platform)
python cleanup_comprehensive.py

# PowerShell script (Windows)
.\cleanup_comprehensive.ps1


# Bash script (Linux/WSL2)
./cleanup_quick.sh

These scripts will remove:

  • *_versions/ directories
  • __pycache__/ directories
  • *.pyc files
  • Update .gitignore with proper patterns

Environment Variables

  • FLASK_ENV - Environment (development/staging/production)

  • DOCKER_HOST - Docker daemon URL (default: unix:///var/run/docker.sock, or tcp://localhost:2375 for Windows)

  • API_KEY - Authentication key for production

  • REDIS_URL - Redis URL for caching (optional)

  • GNOSIS_DOCKER_URL - API endpoint URL (default: http://localhost:5680)

Security

  • Local-only access by default (binds to 127.0.0.1)
  • API key authentication for production deployments
  • Request validation and sanitization
  • Docker socket security with proper permissions and validation
  • CORS protection for web interfaces
  • Container parameter validation prevents dangerous operations
  • Volume mount restrictions limit filesystem access

Development

Running Locally

# Install dependencies
pip install -r requirements.txt

# Or use setup script
.\setup.ps1

# Run in development mode
python app.py


# Run tests
python -m pytest tests/

# Test API endpoints
python test_api.py

Docker Development

# Build container
docker build -t gnosis-docker .

# Or use deployment script
.\deploy.ps1 -Target local

# Run with Docker Compose
docker-compose up -d


# View logs
docker-compose logs -f gnosis-docker

Integration with Gnosis Ecosystem

This Docker controller is designed to work with other Gnosis components:

  • Gnosis Wraith - Web crawling and data extraction
  • Gnosis Mystic - Function interception and analysis
  • Gnosis Stream - Data processing and streaming
  • Gnosis Evolve - Development tools and utilities

The MCP tools provide a unified interface for AI assistants to manage the entire Gnosis ecosystem through Docker containers.

API Usage Examples

List Running Containers

curl http://localhost:5680/api/containers

Start a Container

curl -X POST http://localhost:5680/api/containers/mycontainer/start

Get Container Logs

curl http://localhost:5680/api/containers/mycontainer/logs?tail=100

Build a Gnosis Project

curl -X POST http://localhost:5680/api/build \
  -H "Content-Type: application/json" \
  -d '{"project": "gnosis-wraith", "tag": "latest"}'

Troubleshooting

Common Issues

  1. Docker daemon not accessible in WSL2

    • Check Docker Desktop is running
    • Verify WSL2 integration is enabled in Docker Desktop
    • Check Docker socket exists: ls -la /var/run/docker.sock
    • Restart Docker Desktop and try again
  2. Docker daemon not accessible on Windows

    • Ensure Docker Desktop is running
    • Check if TCP endpoint is enabled (Settings → General)
    • Verify DOCKER_HOST environment variable
    • Try running: .\setup-docker-desktop.ps1
  3. "Cannot connect to Docker daemon" errors

    • WSL2: Check that Docker socket is mounted: docker version
    • Windows: Verify TCP endpoint: curl http://localhost:2375/version
    • Check firewall settings
    • Ensure Docker Desktop has started completely
  4. Container fails to start

    • Check Docker logs: docker-compose logs gnosis-docker
    • Verify port 5680 is not in use: netstat -an | findstr 5680
    • Check volume mounts in docker-compose.yml
  5. Port 5680 already in use

    • Stop existing instances
    • Change port in deployment scripts
    • Check for conflicting services
  6. MCP tools not connecting

    • Verify API server is running on localhost:5680
    • Check firewall settings
    • Ensure MCP dependencies are installed
  7. Path issues with double slashes

    • Use single backslashes in Windows paths
    • WSL2 paths should use /mnt/c/ prefix
    • Docker-compose uses Linux-style paths inside containers
    • Check docker-compose.yml volume mappings

Logs and Debugging

# Check API server logs
docker-compose logs gnosis-docker

# Enable debug logging
export FLASK_ENV=development  # WSL2
$env:FLASK_ENV = "development"  # PowerShell
python app.py

# Test API health
curl http://localhost:5680/health

# Test Docker socket access (WSL2)
docker version
ls -la /var/run/docker.sock

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Update documentation
  6. Submit a pull request

License

This project is part of the Gnosis ecosystem and follows the same licensing terms.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选