33 lines
783 B
Docker
33 lines
783 B
Docker
# --- STAGE 1: Builder ---
|
|
FROM python:3.9-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies needed for building
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install dependencies into a local directory
|
|
COPY requirements.txt .
|
|
RUN pip install --user --no-cache-dir -r requirements.txt
|
|
|
|
# --- STAGE 2: Runtime ---
|
|
FROM python:3.9-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy only installed packages from builder
|
|
COPY --from=builder /root/.local /root/.local
|
|
# Update PATH to include the user-installed packages
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Expose port 8000
|
|
EXPOSE 8000
|
|
|
|
# Command to run the application
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|