paper-dynasty-apiproxy/Dockerfile

39 lines
896 B
Docker

# Stage 1: Build stage
FROM python:3.12-slim AS builder
WORKDIR /app
# Install build dependencies (if needed)
RUN apt-get update && apt-get install -y --no-install-recommends gcc libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements first (cache dependencies)
COPY requirements.txt .
# Install dependencies in a separate directory to copy later
RUN pip install --prefix=/install --no-cache-dir -r requirements.txt
# Copy app source
COPY ./app .
# Stage 2: Final runtime image
FROM python:3.12-slim
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /install /usr/local
# Copy app code
COPY --from=builder /app /app
# Expose port
EXPOSE 8000
# Use a non-root user (optional but recommended)
RUN useradd -m appuser && chown -R appuser /app
USER appuser
# Run the app with Uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]