Spaces:
mxrkai
/
Runtime error

test24 / Dockerfile
Niansuh's picture
Update Dockerfile
e0f8624 verified
raw
history blame
1.51 kB
# Stage 1: Builder
FROM python:3.10-slim AS builder
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables for user installation
ENV PATH=/root/.local/bin:$PATH
# Set the working directory in the builder
WORKDIR /app
# Copy the requirements file first for better caching
COPY requirements.txt /app/
# Install dependencies to /root/.local using --user
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir --user -r requirements.txt
# Stage 2: Production
FROM python:3.10-slim
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables for user installation
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Set the working directory in the container
WORKDIR /app
# Copy installed Python packages from the builder stage
COPY --from=builder /root/.local /root/.local
# Copy the current directory contents into the container
COPY . /app
# Ensure that the Python path includes the local packages
ENV PYTHONPATH=/root/.local/lib/python3.10/site-packages:$PYTHONPATH
# Expose the port that the FastAPI app runs on
EXPOSE 8001
# Command to run the app with Gunicorn and Uvicorn workers
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--workers", "4", "--bind", "0.0.0.0:8001", "main:app"]