# Use the official Python base image from Docker Hub | |
FROM python:3.10-slim | |
# In your Dockerfile | |
# Install system dependencies (like ffmpeg) as root | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
ffmpeg \ | |
aria2 \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create a non-root user named 'app' | |
RUN useradd --create-home app | |
# Set the working directory for the application | |
WORKDIR /code | |
# Copy all application files from your project into the container's working directory | |
COPY . . | |
# Change the ownership of all files and directories within /code. | |
# The -R flag is for "recursive," applying this to everything inside /code. | |
# THIS IS THE KEY FIX: It gives the 'app' user full control of the directory. | |
RUN chown -R app:app /code | |
# Switch from the 'root' user to the 'app' user | |
USER app | |
# Install Python dependencies for the 'app' user | |
RUN pip install --no-cache-dir --user -r requirements.txt | |
# Add the user's local installation directory to the system's PATH | |
ENV PATH="/home/app/.local/bin:${PATH}" | |
# Expose the port the app runs on | |
EXPOSE 7860 | |
# Command to run the application | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |