Docker Deployment¶
Package and run MCP Mesh agents in containers for consistent, portable deployments
Overview¶
Docker provides a consistent environment for running MCP Mesh agents across different systems. This section covers building Docker images for your agents, running multi-agent systems with Docker Compose, and preparing for container orchestration platforms.
Whether you're containerizing a single agent or building a complex multi-service mesh, Docker ensures your agents run the same way everywhere - from your laptop to production servers.
What You'll Learn¶
By the end of this section, you will:
- β Build optimized Docker images for MCP Mesh agents
- β Configure multi-agent systems with Docker Compose
- β Implement service discovery in containerized environments
- β Manage persistent data and configuration
- β Set up networking for agent communication
- β Prepare for Kubernetes deployment
Why Docker for MCP Mesh?¶
Docker solves several challenges in distributed agent deployment:
- Consistency: Same environment everywhere, no "works on my machine"
- Isolation: Agents run in separate containers with defined resources
- Portability: Move from development to production seamlessly
- Scalability: Easy to run multiple instances of agents
- Dependency Management: All dependencies packaged with the agent
Docker Architecture for MCP Mesh¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Docker Host β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β Registry β β Weather Agent β β System β β
β β Container β β Container β β Agent β β
β β β β β β Container β β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββ β
β β β Go Registry β β β β Python Agentβ β β β Python ββ β
β β β PostgreSQL β β β β MCP Mesh β β β β Agent ββ β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββ β
β ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ ββββββββ¬ββββββ β
β β β β β
β ββββββββββ΄βββββββββββββββββββββββ΄βββββββββββββββββββββ΄βββββ β
β β Docker Network (mesh-net) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Section Contents¶
- Building Docker Images - Create optimized images for agents
- Docker Compose Setup - Orchestrate multi-agent systems
- Multi-Agent Deployment - Run complex agent networks
- Networking and Service Discovery - Container communication
- Persistent Storage - Data persistence strategies
Quick Start Example¶
Here's a complete Docker Compose setup to get you started:
# docker-compose.yml
version: "3.8"
services:
registry:
build:
context: .
dockerfile: docker/registry/Dockerfile
ports:
- "8000:8000"
environment:
MCP_MESH_DB_TYPE: postgresql
MCP_MESH_DB_HOST: postgres
MCP_MESH_DB_NAME: mcp_mesh
MCP_MESH_DB_USER: postgres
MCP_MESH_DB_PASSWORD: postgres
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:15-alpine
environment:
POSTGRES_DB: mcp_mesh
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
system-agent:
build:
context: .
dockerfile: docker/agent/Dockerfile
command: ["./bin/meshctl", "start", "examples/simple/system_agent.py"]
environment:
MCP_MESH_REGISTRY_URL: http://registry:8000
depends_on:
- registry
weather-agent:
build:
context: .
dockerfile: docker/agent/Dockerfile
command: ["./bin/meshctl", "start", "examples/simple/weather_agent.py"]
environment:
MCP_MESH_REGISTRY_URL: http://registry:8000
depends_on:
- registry
- system-agent
volumes:
postgres_data:
networks:
default:
name: mesh-net
Run it with:
Key Concepts for Docker Deployment¶
1. Image Layers and Caching¶
Build efficient images with proper layering:
# Good: Layers that change less frequently first
FROM python:3.11-slim
WORKDIR /app
# Install MCP Mesh from source
COPY . .
RUN make install-dev
# Run agent
CMD ["./bin/meshctl", "start", "examples/simple/agent.py"]
2. Environment Configuration¶
Use environment variables for configuration:
# Development
docker run -e MCP_MESH_LOG_LEVEL=DEBUG my-agent
# Production
docker run -e MCP_MESH_LOG_LEVEL=INFO my-agent
3. Health Checks¶
Ensure containers are ready before dependent services start:
Development Workflow with Docker¶
- Build Once, Run Anywhere
- Local Development with Bind Mounts
- Multi-Stage Builds for Optimization
Best Practices¶
- π Security: Never embed secrets in images
- π¦ Size: Use slim base images and multi-stage builds
- π·οΈ Tagging: Use semantic versioning for image tags
- π Documentation: Include README in image with usage instructions
- π Updates: Regularly update base images for security patches
Ready to Start?¶
Begin with Building Docker Images β
π§ Troubleshooting¶
Common Docker Issues¶
-
Container can't connect to registry
-
Check network configuration
- Verify service names in compose file
-
Ensure registry is healthy before agents start
-
Agent exits immediately
-
Check logs:
docker logs <container> - Verify CMD or ENTRYPOINT is correct
-
Ensure required environment variables are set
-
Permission denied errors
- Run containers as non-root user
- Check file permissions in image
- Use proper volume mount permissions
For detailed solutions, see our Docker Troubleshooting Guide.
β οΈ Known Limitations¶
- Windows Containers: Limited support, use Linux containers
- ARM Architecture: Some base images may not support ARM
- File Watching: Hot reload doesn't work well in containers
- Networking: Container networking adds complexity to debugging
π TODO¶
- Add Kubernetes deployment examples
- Create automated image vulnerability scanning
- Add examples for cloud container registries
- Document multi-architecture builds
- Add container security best practices guide
π‘ Tip: Use Docker BuildKit for faster builds: DOCKER_BUILDKIT=1 docker build .
π Reference: Official Docker Documentation
π― Next Step: Ready to containerize your agents? Start with Building Docker Images