Docker Compose MCP server

Manage Docker containers, bridged by the Docker SDK for Python.
Back to servers
Provider
ckreiling
Release date
Dec 07, 2024
Language
Python
Stats
459 stars

Docker MCP is a server that allows you to manage Docker containers using natural language instructions. It enables you to create, configure, and manage Docker containers through conversational interfaces, making Docker more accessible to users without extensive command-line experience.

Installation Options

Using Claude Desktop

You'll need to modify the Claude Desktop configuration file to integrate the Docker MCP server:

On MacOS:

Edit this file: ~/Library/Application\ Support/Claude/claude_desktop_config.json

On Windows:

Edit this file: %APPDATA%/Claude/claude_desktop_config.json

Installing from PyPi with uv

  1. First install uv by following the instructions at the official documentation

  2. Add the following to your MCP servers configuration file:

"mcpServers": {
  "mcp-server-docker": {
    "command": "uvx",
    "args": [
      "mcp-server-docker"
    ]
  }
}

Installing with Docker

  1. Clone the repository
  2. Build the Docker image:
docker build -t mcp-server-docker .
  1. Add the following to your MCP servers configuration file:
"mcpServers": {
  "mcp-server-docker": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "-v",
      "/var/run/docker.sock:/var/run/docker.sock",
      "mcp-server-docker:latest"
    ]
  }
}

Note: The Docker socket is mounted as a volume to allow the MCP server to interact with your local Docker daemon.

Using Docker MCP

Docker Compose with Natural Language

The docker_compose prompt allows you to create and manage Docker containers using natural language descriptions.

How It Works

  1. Provide a project name and describe the containers you want to deploy
  2. The system will generate a plan based on your description
  3. You can either apply the plan or provide feedback for adjustments

Example Usage

You can deploy containers with simple instructions like:

  • name: nginx, containers: "deploy an nginx container exposing it on port 9000"
  • name: wordpress, containers: "deploy a WordPress container and a supporting MySQL container, exposing Wordpress on port 9000"

Resuming Projects

When starting a new chat with the docker_compose prompt, the system will retrieve the status of any containers, volumes, and networks associated with your project name, allowing you to manage or clean up resources from previous sessions.

Available Resources

The server provides these resources for container management:

  • Stats: CPU, memory, and other performance metrics
  • Logs: Access container logs directly

Available Tools

Container Management

  • list_containers
  • create_container
  • run_container
  • recreate_container
  • start_container
  • fetch_container_logs
  • stop_container
  • remove_container

Image Management

  • list_images
  • pull_image
  • push_image
  • build_image
  • remove_image

Network Management

  • list_networks
  • create_network
  • remove_network

Volume Management

  • list_volumes
  • create_volume
  • remove_volume

Security Considerations

Handling Sensitive Data

Important: Do not configure containers with sensitive data like API keys or database passwords. Any sensitive information exchanged with the LLM may be compromised unless the LLM is running locally.

Container Review

Always review the containers created by the system. Docker containers can potentially impact your host machine, so verify configurations before applying them.

For safety, this MCP server doesn't support potentially dangerous Docker options like --privileged or --cap-add/--cap-drop.

Advanced Configuration

Docker SDK Configuration

This server uses the Python Docker SDK's from_env method. See the official documentation for configuration details.

Connecting to Docker over SSH

To connect to a remote Docker daemon over SSH, set the DOCKER_HOST environment variable in your MCP server definition:

"mcpServers": {
  "mcp-server-docker": {
    "command": "uvx",
    "args": [
      "mcp-server-docker"
    ],
    "env": {
      "DOCKER_HOST": "ssh://[email protected]"
    }
  }
}

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later