FROM python:3.10 # 1. Set a temporary working directory WORKDIR /code # 2. Copy just the requirements first and install them GLOBALLY COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # 3. Create the restricted user required by Hugging Face Spaces RUN useradd -m -u 1000 user # 4. Switch to that user USER user # 5. Set up the user's safe environment variables ENV HOME=/home/user ENV PATH=/home/user/.local/bin:$PATH # 6. Set the working directory to the user's safe space WORKDIR $HOME/app # 7. Copy your app.py and images into the container, owned by the safe user COPY --chown=user:user . $HOME/app # 8. Launch Streamlit safely CMD ["streamlit", "run", "app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]