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.
Generate & Test Docker MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
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)
Build your full agent toolstack in the Visual Generator
Combine Docker with databases, search APIs, and memory graphs in a single configuration file.
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.