FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime # Create a new user with user ID 1000 RUN useradd -m -u 1000 user # Set environment variables for cache ENV HF_HOME=/home/user/cache # Switch to the new user USER user WORKDIR /home/user/app # Create the cache directory with correct ownership and permissions RUN mkdir -p /home/user/cache && chmod -R 777 /home/user/cache # Copy application files with ownership set to the new user COPY --chown=user . /home/user/app # Install Python dependencies, including uvicorn RUN pip install --no-cache-dir -r requirements.txt uvicorn # Expose the application port EXPOSE 7860 # Run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]