Deploy MCP with Docker
FROM python:3.12-slim WORKDIR /app COPY . /app RUN pip install --no-cache-dir -r requirements.txt RUN useradd -r appuser && chown -R appuser /app USER appuser CMD ["python", "server.py"]
Container principles
- Run as non-root.
- Do not bake API keys into layers.
- Pin dependencies.
- Keep filesystem permissions minimal.
- Set CPU/memory limits in the runtime.
State
The modern protocol core is stateless, so avoid storing protocol session state in container memory. Application state belongs in durable stores when needed.