SamuelJaja's picture
Update Dockerfile
ea3018d verified
# Use NVIDIA CUDA base image for GPU support
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV HF_HOME=/app/cache
ENV TRANSFORMERS_CACHE=/app/cache
# Install Python and other dependencies
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
python3-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Set Python alias
RUN ln -sf /usr/bin/python3 /usr/bin/python
# Create a non-root user with a home directory
RUN useradd -m -u 1000 appuser
# Set the working directory
WORKDIR /app
# Copy requirements and install dependencies first (for better caching)
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
# Create directories with appropriate permissions
RUN mkdir -p /app/cache && chown -R appuser:appuser /app
# Copy the application code
COPY . .
RUN chown -R appuser:appuser /app
# Switch to the non-root user
USER appuser
# Expose the application port
EXPOSE 8000
# Run the FastAPI application with log level
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]