# Use the lightweight Python 3.9 image based on Debian Buster FROM python:3.10-slim-buster # Set the working directory inside the container WORKDIR /app # Copy just the requirements.txt first to leverage Docker cache COPY requirements.txt . # Install Python dependencies without storing cache, for a smaller image RUN pip install --no-cache-dir --upgrade -r requirements.txt # Update package lists and install FFmpeg for media processing RUN apt-get update && apt-get install -y ffmpeg RUN useradd -m -u 1000 user # Switch to root user to change directory ownership USER root RUN mkdir -p /usr/share/nltk_data && chown -R user:user /usr/share/nltk_data USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR $HOME/app # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/app # Set environment variables for NLTK data and Matplotlib configuration ENV NLTK_DATA /usr/share/nltk_data ENV MPLCONFIGDIR /tmp/matplotlib # Create and set permissions for result directories and logs inside the container # Using a loop can reduce the number of layers and make the Dockerfile cleaner RUN for dir in results logs; do \ mkdir $HOME/app/$dir && chmod -R 777 $HOME/app/$dir; \ done # Copy all Python files from the current directory to the container COPY *.py . RUN python setup.py # Specify the command to run on container start CMD ["python", "app.py"]