- Add documentation links in main README overview section - Create new Documentation section listing all README files - Ensure all README files are properly referenced - All server documentation is now easily discoverable 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.1 KiB
6.1 KiB
Portainer Docker MCP Server
This MCP server provides comprehensive Docker and Docker Swarm management functionality through Portainer Business Edition.
Features
Container Management
-
List and Inspect Containers
- View all containers with status, ports, and resource usage
- Get detailed container information including networks, mounts, and environment
- Support for both running and stopped containers
-
Container Lifecycle
- Create containers with custom configurations
- Start, stop, and restart containers
- Remove containers (with force option)
- View container logs with tail and timestamp options
Image Management
- Docker Images
- List all images with sizes and tags
- Pull images from registries
- Remove unused images
- Support for multi-tag images
Volume Management
- Docker Volumes
- List volumes with mount points
- Create named volumes
- Remove volumes
- Support for different volume drivers
Network Management
- Docker Networks
- List networks with details
- Create custom networks (bridge, overlay, etc.)
- Remove networks
- Configure internal networks
Docker Swarm Features
-
Service Management
- List services with replica status
- Create services with scaling options
- Update service configurations
- Remove services
- View service logs
-
Stack Deployment
- Deploy stacks from Docker Compose files
- List stacks across environments
- Remove stacks with all resources
- Support for environment variables in stacks
System Information
- Docker Info
- System-wide Docker information
- Resource usage statistics
- Swarm cluster status
- Version information
Installation
- Ensure Python dependencies are installed:
pip install mcp httpx aiohttp
# Or use the requirements file:
pip install -r requirements.txt
- Configure in Claude Desktop (
claude_desktop_config.json
):
{
"mcpServers": {
"portainer-docker": {
"command": "python",
"args": ["/path/to/portainer-mcp/portainer_docker_server.py"],
"env": {
"PORTAINER_URL": "https://your-portainer-instance.com",
"PORTAINER_API_KEY": "your-api-key",
"MCP_MODE": "true"
}
}
}
}
- Restart Claude Desktop
Available Tools
Container Operations
list_containers
- List all containers in an environmentinspect_container
- Get detailed container informationcreate_container
- Create a new containerstart_container
- Start a stopped containerstop_container
- Stop a running containerrestart_container
- Restart a containerremove_container
- Remove a containerget_container_logs
- View container logs
Image Operations
list_images
- List Docker imagespull_image
- Pull an image from registryremove_image
- Remove an image
Volume Operations
list_volumes
- List Docker volumescreate_volume
- Create a new volumeremove_volume
- Remove a volume
Network Operations
list_networks
- List Docker networkscreate_network
- Create a new networkremove_network
- Remove a network
Swarm Service Operations
list_services
- List Swarm servicescreate_service
- Create a new serviceupdate_service
- Update service configurationremove_service
- Remove a serviceget_service_logs
- View service logs
Stack Operations
list_stacks
- List deployed stacksdeploy_stack
- Deploy a new stackremove_stack
- Remove a stack
System Operations
get_docker_info
- Get Docker system informationget_docker_version
- Get Docker version details
Usage Examples
Container Management
# List all containers in environment 3
Use "list_containers" with environment_id: 3, all: true
# Create and start an nginx container
Use "create_container" with:
- environment_id: 3
- image: "nginx:latest"
- name: "my-nginx"
- ports: {"80/tcp": [{"HostPort": "8080"}]}
# View container logs
Use "get_container_logs" with:
- environment_id: 3
- container_id: "my-nginx"
- tail: 50
- timestamps: true
Docker Swarm Services
# Create a replicated service
Use "create_service" with:
- environment_id: 4
- name: "web-service"
- image: "nginx:alpine"
- replicas: 3
- ports: [{"target": 80, "published": 8080, "protocol": "tcp"}]
# Scale a service
Use "update_service" with:
- environment_id: 4
- service_id: "web-service"
- replicas: 5
Stack Deployment
# Deploy a stack
Use "deploy_stack" with:
- environment_id: 4
- name: "my-app"
- compose_file: |
version: '3.8'
services:
web:
image: nginx:alpine
ports:
- "8080:80"
redis:
image: redis:alpine
Docker Volumes
# Create a volume
Use "create_volume" with:
- environment_id: 3
- name: "app-data"
- driver: "local"
# List volumes
Use "list_volumes" with environment_id: 3
Container Configuration
When creating containers, you can specify:
- Image: Docker image name with optional tag
- Name: Container name (optional)
- Command: Override default command
- Environment Variables: Array of KEY=VALUE strings
- Ports: Port bindings (host:container mapping)
- Volumes: Volume mounts
- Restart Policy: no, always, unless-stopped, on-failure
Swarm vs Standalone
This server automatically handles both:
- Docker Standalone: Container operations, local volumes, bridge networks
- Docker Swarm: Services, stacks, overlay networks, multi-node deployments
Some operations (like services) only work on Swarm environments.
Error Handling
The server provides clear error messages:
- Environment not found
- Container/service not found
- Swarm-only operations on standalone Docker
- Network connectivity issues
- Permission errors
Security Notes
- API key is required for all operations
- Container operations respect Portainer's RBAC
- Sensitive environment variables are filtered from logs
- Force options available for cleanup operations
Limitations
- Log output is limited to prevent overwhelming responses
- Large container lists are truncated (shows first 20)
- Stack deployment requires compose file as string
- Some Docker features may require direct API access