# MCP LangChain Agent Dockerfile
# Multi-stage build for optimized production image
# Build stage
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy project files
WORKDIR /app
COPY pyproject.toml ./
COPY README.md ./
# Install dependencies
RUN pip install --upgrade pip && \
pip install -e .
# Production stage
FROM python:3.11-slim as production
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/opt/venv/bin:$PATH"
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r langchain && useradd -r -g langchain langchain
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
# Copy application code
WORKDIR /app
COPY . .
# Set ownership
RUN chown -R langchain:langchain /app
# Switch to non-root user
USER langchain
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Expose port
EXPOSE 8000
# Default command
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]