Custom MCP in Docker Container Creates New Containers Without Stopping Old Ones

Hi Guys!

I’m working on a custom MCP server running as a Docker container in Cursor IDE, but I’m running into an issue. Every time Cursor starts the MCP server, it creates a new container from my Docker image, and the previous containers remain running indefinitely. This leads to multiple orphaned containers piling up on my system.

Here’s my setup:
mcp.json:

{
  "mcpServers": {
    "fmt ": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "fmt-mcp-server"
      ]
    }
  }
}

docker ps:

CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                       NAMES
c76feb7bfd26   fmt-mcp-server         "python main.py"         47 seconds ago   Up 47 seconds                               youthful_lovelace
8b6b662455ac   fmt-mcp-server         "python main.py"         49 seconds ago   Up 49 seconds                               brave_yalow
0d892c19df16   fmt-mcp-server         "python main.py"         49 seconds ago   Up 49 seconds                               nifty_haslett
706f068645a1   fmt-mcp-server         "python main.py"         17 minutes ago   Up 17 minutes                               unruffled_babbage
24f061bdb4ad   fmt-mcp-server         "python main.py"         17 minutes ago   Up 17 minutes                               suspicious_euclid
915280bd237e   fmt-mcp-server         "python main.py"         18 minutes ago   Up 18 minutes                               bold_fermi

thanks

2 Likes

I am having the same issue, which makes it difficult to use containers as mcp servers.

1 Like

I’m facing the same issue. This is very easy to reproduce. Try the following mcp server for example:

{
  "mcpServers": {
    "mcp-atlassian": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "JIRA_URL",
        "-e", "JIRA_USERNAME",
        "-e", "JIRA_API_TOKEN",
        "ghcr.io/sooperset/mcp-atlassian:latest"
      ],
      "env": {
        "JIRA_URL": "https://your-company.atlassian.net",
        "JIRA_USERNAME": "[email protected]",
        "JIRA_API_TOKEN": "your_jira_api_token"
      }
    }
  }
}

it will constantly start new containers. the only way around this is to name the container e.g. "--name", "mcp-atlassian". However, if you try to refresh the container, it will error out sine obviously, a container with the same name already exists.

This seems like a simple fix – when an mcp container is refreshed, you need to kill old containers.