Dev Tools·
advanced
·12 min read·Apr 4, 2026

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.

DockercontainersDevOpsinfrastructuredeployment

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:

json
{
  "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 container stdout and stderr logs.
  • 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 nginx image 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 the docker.sock. Ensure Docker Desktop is actually running. If you are on Linux, you may need to add the user running the MCP server to the docker group.
  • 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:

bash
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