Provides secure Docker command execution capabilities, including container and image management, Docker Compose operations, and system information retrieval through validated command execution on the host system.
MCP Docker Server
A Python-based MCP (Model Context Protocol) server that provides secure Docker command execution for language models or other clients running in isolated environments like containers.
Overview
This MCP server runs on a host system and provides access to its Docker daemon via the MCP protocol. It implements security filtering and command validation to ensure safe operation, only allowing docker and docker-compose commands to be executed.
Features
Docker Command Execution: Executes
dockeranddocker-composecommands on the host.Docker Compose Support: Handles both legacy
docker-composeand moderndocker composesyntax.Security Validation: An explicit allowlist restricts executable commands to
dockeranddocker-composeonly.Async I/O: Built with
asynciofor non-blocking command execution.Multiple Transports: Supports
stdio,sse, andstreamable-httpMCP transports.Rich Toolset: Provides specific tools for common operations like listing containers, images, and checking system info.
Error Handling: Returns detailed error messages for failed commands.
Architecture
Installation
Python: Requires Python 3.12 or newer.
Docker: Docker must be installed and the daemon must be running on the host system.
Dependencies: Install the required Python packages using
uvorpipfrompyproject.toml.# Using uv uv pip install -r requirements.txt # Or directly from the pyproject.toml uv pip install .
Usage
Starting the Server
The server can be started with different MCP transports.
Environment Variables
Configure the server's network binding with these environment variables.
FASTMCP_HOST: Server bind address (default:0.0.0.0for container access).FASTMCP_PORT: Server port (default:3000).
You can create a .env file to manage these variables:
Then run the server with:
MCP Protocol
The server uses the mcp library to expose tools. The available transports are stdio, sse, and streamable-http.
Available Methods (Tools)
The following tools are exposed by the server:
execute_docker_command(command: str, working_directory: str = None) -> strDescription: Executes a general Docker or Docker Compose command. The command is validated against an allowlist.
Example:
session.call_tool("execute_docker_command", {"command": "docker ps -a"})
docker_system_info() -> strDescription: Retrieves Docker version and system disk usage information.
Example:
session.call_tool("docker_system_info", {})
list_containers(all: bool = False) -> strDescription: Lists Docker containers.
Args:
all(boolean) - If true, shows all containers (including stopped ones). Defaults toFalse.Example:
session.call_tool("list_containers", {"all": True})
list_images(all: bool = False) -> strDescription: Lists Docker images.
Args:
all(boolean) - If true, shows all images (including intermediate ones). Defaults toFalse.Example:
session.call_tool("list_images", {})
docker_compose_status(working_directory: str = None) -> strDescription: Gets the status of services defined in a
docker-compose.ymlfile.Args:
working_directory(string) - The path to the directory containing the compose file.Example:
session.call_tool("docker_compose_status", {"working_directory": "/path/to/project"})
Security Features
Command Validation
The server uses an allowlist-based approach for security. The is_allowed_command method in main.py ensures that only commands beginning with docker or docker-compose (including docker compose) are processed. All other commands are rejected.
Error Handling
If a command fails to execute, the server captures stdout, stderr, and the exit code, returning a detailed error message to the client. The execute_command function contains a try...except block to handle exceptions during subprocess execution.
Troubleshooting
Common Issues
Docker Not Available:
Ensure Docker is installed:
docker --versionCheck that the Docker daemon is running:
docker infoVerify your user has permissions to access the Docker socket.
Port Already in Use:
If you see an error like
address already in use, the port (default3000) is occupied.Change the port using the
FASTMCP_PORTenvironment variable.Find the process using the port:
lsof -i :3000ornetstat -tulnp | grep 3000.
Permission Denied (Docker Socket):
If you get a "permission denied" error when running Docker commands, add your user to the
dockergroup:sudo usermod -aG docker $USER.You will need to start a new shell session for this change to take effect.
Connection Refused:
Verify the MCP server is running and listening on the correct host and port.
Check for firewall rules that might be blocking the connection.
Ensure your client configuration matches the server's
FASTMCP_HOSTandFASTMCP_PORT.
Development
Project Structure
Testing
Run the example test client to connect to a running server, list its tools, and execute a sample command.
License
This project is open-source and available for modification and distribution.
Support
For issues and questions:
Check the Troubleshooting section.
Verify your Docker installation and permissions.
Review the server logs for error details.
Test connectivity with simple commands first (e.g.,
docker_system_info).
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables secure Docker command execution from isolated environments like containers through MCP protocol. Provides tools for managing Docker containers, images, and Docker Compose services with security validation and async operation support.
Related MCP Servers
- -security-license-qualityAn MCP server to create secure code sandbox environment for executing code within Docker containers.Last updated -269MIT License
 - -security-license-qualityAn MCP server that allows managing Docker containers through natural language, enabling users to compose, introspect, and debug containers without running commands themselves.Last updated -618GPL 3.0
 - Asecurity-licenseAqualityAllows Claude and other AI assistants to interact with Docker through the MCP protocol, enabling container and image management including listing, running, stopping, and pulling Docker resources.Last updated -6314
 - Asecurity-licenseAqualityAllows executing shell commands within a secure Docker container through Claude's MCP interface, providing Kubernetes tools and isolated environment without host Docker daemon access.Last updated -2315MIT License