# Use Debian-based Python 3.13 slim image FROM python:3.13-slim-bookworm # Set working directory WORKDIR /app # Install system dependencies for rrdtool RUN apt-get update && apt-get install -y \ rrdtool \ librrd-dev \ build-essential \ python3-dev \ wget \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better Docker layer caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Remove build dependencies to reduce image size RUN apt-get purge -y build-essential python3-dev && \ apt-get autoremove -y && \ apt-get clean # Copy application code COPY app/ ./app/ # Create directory for RRD data RUN mkdir -p /app/data # Expose port EXPOSE 8000 # Create non-root user for security RUN useradd --create-home --shell /bin/bash appuser && \ chown -R appuser:appuser /app USER appuser # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:8000/health || exit 1 # Run the application CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]