FROM python:3.11 ENV USERNAME=admin # Create and use a non-root user RUN useradd -ms /bin/bash $USERNAME # Set working directory for the application WORKDIR /app # 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 git-all \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* ENV HOME=/home/$USERNAME RUN mkdir $HOME/.cache $HOME/.config \ && chmod -R 777 $HOME ENV PATH=$HOME/.local/bin:$PATH COPY init.sh /app/init.sh RUN chmod +x /app/init.sh RUN /app/init.sh # 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 # Use init.sh as the entrypoint so it runs on container start ENTRYPOINT ["/app/init.sh"] CMD ["python", "-u", "-m", "FileServer"]