FROM python:3.11 | |
# Create and use a non-root user | |
RUN useradd -ms /bin/bash admin | |
# Set working directory for the application | |
WORKDIR /app | |
# Copy only the necessary files first for better cache utilization | |
COPY requirements.txt /app/requirements.txt | |
# Install system dependencies and clean up in a single RUN step to reduce layers | |
RUN apt-get update -y && apt-get upgrade -y \ | |
&& apt-get install -y \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Install Python dependencies from the requirements file | |
RUN pip3 install --no-cache-dir --upgrade -r requirements.txt | |
# Copy the rest of the application code after installing dependencies for better cache | |
COPY . /app | |
# Set ownership and permissions for the app directory | |
RUN chown -R admin:admin /app && chmod -R 777 /app | |
# Switch to the non-root user for better security | |
USER admin | |
# Expose the port the application will run on | |
EXPOSE 7860 | |
# Command to run the application | |
CMD ["python", "-u", "-m", "FileStream"] | |