DO

Docker Container Management for MCP Server

Manage Docker containers, images, volumes and networks on your MCP server for streamlined deployment, scaling and backup.

Quick Install
npx -y @ckreiling/mcp-server-docker

Overview

This repository provides tooling and Docker configuration to manage an MCP (Model Context Protocol) server along with its containers, images, volumes, and networks. It bundles Dockerfiles, docker-compose templates, and helpful commands that simplify deploying, scaling, and backing up MCP environments. The result is a repeatable, containerized setup suitable for development, testing and production staging.

Using Docker to host the MCP server isolates dependencies, enables fast rollbacks by switching container images, and makes horizontal scaling straightforward. The included templates and scripts reduce manual Docker operations so you can focus on model orchestration and integration with your application stack.

Features

  • Dockerfiles and docker-compose templates for running an MCP server and related services
  • Commands and examples for building images, running containers, and managing networks/volumes
  • Volume backup and restore patterns for preserving model state and data
  • Scalable service patterns (compose scaling and recommended practices)
  • Environment-driven configuration for easy deployment to different environments (dev/stage/prod)
  • Guidance for pruning and housekeeping of images, containers and volumes

Installation / Configuration

Clone the repository and bring up the stack using Docker Compose:

# Clone the repo
git clone https://github.com/ckreiling/mcp-server-docker.git
cd mcp-server-docker

# Build and start services (docker-compose v1/v2)
docker-compose build
docker-compose up -d

If you use the Docker Compose plugin:

docker compose build
docker compose up -d

Minimum example .env file (place alongside docker-compose.yml):

# .env
MCP_IMAGE=mcp-server:latest
MCP_PORT=8080
MCP_DATA_VOLUME=mcp_data
LOG_LEVEL=info

Example docker-compose.yml snippet:

version: "3.8"
services:
  mcp-server:
    image: "${MCP_IMAGE}"
    ports:
      - "${MCP_PORT}:8080"
    environment:
      - LOG_LEVEL=${LOG_LEVEL}
    volumes:
      - ${MCP_DATA_VOLUME}:/var/lib/mcp
    networks:
      - mcp-net

  worker:
    image: "${MCP_IMAGE}"
    command: ["mcp-worker"]
    depends_on:
      - mcp-server
    networks:
      - mcp-net

volumes:
  ${MCP_DATA_VOLUME}:

networks:
  mcp-net:
    driver: bridge

Common Docker commands:

# View running containers
docker ps

# View logs
docker-compose logs -f mcp-server

# Scale worker service
docker-compose up -d --scale worker=3

# Stop and remove all containers defined by compose
docker-compose down --volumes

Available Resources

  • Dockerfile(s): build a production or development image for the MCP server
  • docker-compose templates: multi-service orchestration with volumes and networks
  • Example .env: environment variables to configure ports, images and volumes
  • Backup/restore patterns: sample commands to archive and restore volumes
  • Housekeeping tips: commands for pruning unused images/volumes

Reference table: common maintenance commands

PurposeCommand
Build imagesdocker-compose build
Start servicesdocker-compose up -d
Tail logsdocker-compose logs -f service-name
Scale servicesdocker-compose up -d –scale service=N
Backup volumedocker run –rm -v mcp_data:/data -v $(pwd):/backup alpine tar czf /backup/mcp_data.tgz -C /data .
Restore volumedocker run –rm -v mcp_data:/data -v $(pwd):/backup alpine sh -c “tar xzf /backup/mcp_data.tgz -C /data”
Prune unuseddocker system prune -af –volumes

Use Cases

  1. Deploy a single-node MCP server for development

    • Clone the repo, update .env for a development image and port, then:
    docker-compose up -d
    
    • Connect your app to http://localhost:${MCP_PORT}.
  2. Scale background workers for model inference

    • Increase workers to process more requests:
    docker-compose up -d --scale worker=4
    
    • Monitor CPU and memory to decide appropriate scaling.
  3. Preserve model state and perform backups

    • Create a compressed backup of the MCP data volume:
    docker run --rm -v mcp_data:/data -v $(pwd):/backup alpine \
      tar czf /backup/mcp_data_$(date +%F).tgz -C /data .
    
    • Restore the backup to a fresh volume using the restore command in the table above.
  4. Isolate environments with custom networks and env files

    • Use separate docker-compose.yml overlays or distinct .env files for staging and production.
    • Example:
    docker-compose --env-file .env.staging up -d
    

Notes and best practices

  • Keep persistent data in named Docker volumes (not in container layers).
  • Use environment variables and secrets management for credentials.
  • For production, consider using a container orchestrator (Kubernetes, Swarm) for stronger resilience and automated scaling.
  • Regularly prune unused images/volumes and rotate backups to keep disk usage under control.

This repository is intended to accelerate Docker-based deployments of MCP servers. Use the templates as a baseline and adjust images, networks and volumes to fit your infrastructure and operational policies.

Tags:media