# Use an official Python runtime as a parent image | |
FROM python:3.9 | |
# Set the working directory in the container | |
WORKDIR /app | |
# Create a group and user for running the application | |
RUN groupadd mygroup && useradd -ms /bin/bash -G mygroup appuser | |
# Copy the current directory contents into the container at /app | |
# Use --chown to set the ownership and --chmod to set the permissions | |
COPY --chown=appuser:mygroup . /app | |
# Install any needed packages specified in requirements.txt | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Make port 7860 available to the world outside this container | |
EXPOSE 7860 | |
# Define environment variable for Gradio server port | |
ENV GRADIO_SERVER_PORT=7860 | |
# Set the HF_HOME environment variable to a writable directory | |
ENV HF_HOME=/app/.cache/huggingface | |
# Create the cache directory if it doesn't exist and set its ownership | |
RUN mkdir -p $HF_HOME && chown -R appuser:mygroup $HF_HOME | |
# Switch to the appuser to run the application | |
USER appuser | |
# Run app.py when the container launches | |
CMD ["python", "app.py"] | |