Dockerfile Guide for MCP Servers
Learn how to configure your Dockerfile for MCP server deployment.Requirements
- Linux Base Image: Only Linux images are supported (Alpine or Debian-based recommended).
- Shell Support: Your image must support
sh(the default shell for most Linux distros). - Other Distros: Other Linux distributions are untested and may not deploy successfully.
Example Dockerfile
A minimal Dockerfile for a Python-based MCP server:Best Practices
- Use Minimal Base Images: Start with the smallest image that meets your needs (e.g.,
python:3.11-slimoralpine). - Multi-Stage Builds: Use multi-stage builds to reduce final image size and improve security.
- Layer Caching: Order Dockerfile instructions to maximize build cache efficiency.
- Pin Dependencies: Use a
requirements.txtor similar to pin dependency versions for reproducibility. - Health Checks: Optionally add a
HEALTHCHECKinstruction to help deployment systems detect readiness.