test24 / Dockerfile
Niansuh's picture
Upload 14 files
381d345 verified
raw
history blame contribute delete
868 Bytes
# Use the official Python 3.10 slim image
FROM python:3.10-slim
# Set environment variables to prevent Python from writing pyc files and to buffer stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set the working directory to /app
WORKDIR /app
# Install system dependencies to get `nproc` (for number of CPU cores)
RUN apt-get update && apt-get install -y procps
# Copy only the requirements.txt first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY . .
# Expose port 8001 to the outside world
EXPOSE 8001
# Command to run Uvicorn with a dynamic number of workers based on the CPU cores
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 8001 --workers $(nproc)"]