Skip to main content

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:
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "server.py"]

Best Practices

  • Use Minimal Base Images: Start with the smallest image that meets your needs (e.g., python:3.11-slim or alpine).
  • 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.txt or similar to pin dependency versions for reproducibility.
  • Health Checks: Optionally add a HEALTHCHECK instruction to help deployment systems detect readiness.

Example: Multi-Stage Build

FROM python:3.11-slim as builder
WORKDIR /app
COPY . .
RUN pip install --upgrade pip && pip install -r requirements.txt

FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /app /app
CMD ["python", "server.py"]

Testing

Always test your Docker image locally before deploying. Ensure it starts your Streamable HTTP server as expected.