Docker MCP Server
local-only server
The server can only run on the client’s local machine because it depends on local resources.
Integrations
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:Copy
- Create a virtual environment:Copy
- Install required packages:Copy
Usage
Running the MCP Inspector
To test and explore the server's functionality:
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
Python Data Analysis Example
Node.js Example
Package Manager Support
The Docker MCP server automatically detects and uses the appropriate package manager:
- Python containers: Uses
pip
- Node.js containers: Uses
npm
- Debian/Ubuntu containers: Uses
apt-get
- Alpine containers: Uses
apk
For containers where the package manager isn't obvious from the image name, the server attempts to detect available package managers.
Integrating with Claude and Other LLMs
This MCP server can be integrated with Claude and other LLMs that support the Model Context Protocol. Use the fastmcp install
command to register it with Claude:
Troubleshooting
- Port Already in Use: If you see "Address already in use" errors, ensure no other MCP Inspector instances are running.
- Docker Connection Issues: Verify that Docker is running with
docker --version
. - Container Timeouts: The server includes fallback mechanisms for containers that don't respond within expected timeframes.
- Package Installation Failures: Check that the package name is correct for the specified package manager.
- No Containers Found: If list_containers shows no results, Docker might not have any containers created yet.
Security Considerations
This server executes code in Docker containers, which provides isolation from the host system. However, exercise caution:
- Don't expose this server publicly without additional security measures
- Be careful when mounting host volumes into containers
- Consider resource limits for containers to prevent DoS attacks
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
This server cannot be installed
Facilitates isolated code execution within Docker containers, enabling secure multi-language script execution and integration with language models like Claude via the Model Context Protocol.
- Features
- Requirements
- Installation
- Usage
- Package Manager Support
- Integrating with Claude and Other LLMs
- Troubleshooting
- Security Considerations
- License
- Contributing