How to Use the Docker MCP Server for Container Management
Manage Docker containers, images, and volumes through your AI agent using the Docker MCP server. Build, run, and monitor containers with natural language.
Use the Docker MCP Server for Container Management
The Docker MCP server connects your AI agent directly to the Docker daemon. This allows your agent to manage your local infrastructure, spin up ephemeral test environments, monitor resource usage, and build new container images entirely through natural language commands.
Prerequisites
- ▸Docker Desktop or the Docker Engine installed.
- ▸The Docker daemon running in the background.
- ▸Node.js 18+ installed on your host machine.
Configuration Setup
Add this configuration to your MCP client:
{
"mcpServers": {
"docker": {
"command": "npx",
"args": ["-y", "mcp-server-docker"]
}
}
}Available Tools
The agent is granted an extensive set of tools categorized by function:
Container Operations
- ▸
list_containers— List running and stopped containers. - ▸
create_container— Create new containers from images. - ▸
start_container/stop_container— Manage container lifecycle. - ▸
remove_container— Delete containers. - ▸
container_logs— View containerstdoutandstderrlogs. - ▸
container_stats— Get live resource usage statistics (CPU, Memory).
Image Operations
- ▸
list_images— List available local images. - ▸
pull_image— Pull new images from Docker Hub or private registries. - ▸
build_image— Build images dynamically from Dockerfiles. - ▸
remove_image— Delete unused images.
Volume & Network Operations
- ▸
list_volumes/create_volume— Manage persistent storage. - ▸
list_networks— List Docker bridge networks.
Example Workflows
- ▸Container Monitoring: "Show me all running containers and their current CPU usage. If any are over 80%, fetch their last 50 lines of logs."
- ▸Quick Deployment: "Pull the latest
nginximage and run it on port 8080 with the name 'web-server'." - ▸Cleanup: "List all stopped containers and remove them, then prune any dangling unused images to free up disk space."
Security Considerations & Troubleshooting
- ▸Root Access Warning: Giving an AI agent full access to the Docker socket is effectively giving it root access to your host machine. The agent can mount your host filesystem (
/) into a privileged container. Never run this in a production environment without strict RBAC or socket filtering. - ▸
Cannot connect to the Docker daemon: The MCP server is failing to locate thedocker.sock. Ensure Docker Desktop is actually running. If you are on Linux, you may need to add the user running the MCP server to thedockergroup. - ▸Pull Limits: If the agent attempts to pull images repeatedly, you may hit Docker Hub's anonymous rate limits. Configure your host Docker engine with authentication to bypass this.
Using with OpenAI Codex
To use this MCP server with the OpenAI Codex CLI, you can add it to your configuration using the codex mcp add command:
codex mcp add --name docker --command "npx @modelcontextprotocol/server-docker"(Note: Depending on the server, you may need to append arguments or use --env flags for environment variables as described in the configuration section above)
Related Guides
How to Build a Custom MCP Server from Scratch
Learn how to create your own MCP server using the TypeScript or Python SDK. Expose custom tools and resources for AI agents to use.
Dev ToolsHow to Use the Puppeteer MCP Server for Web Scraping & Automation
Automate web browsers using the Puppeteer MCP server. Navigate websites, take screenshots, extract data, and automate web interactions through AI.
Dev ToolsHow to Use the Git MCP Server for Version Control Operations
Manage local Git repositories through AI agents. Clone repos, create branches, make commits, and view diffs using the Git MCP server.