# Use the official Python image from the Docker Hub FROM python:3.10-slim # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ software-properties-common \ git \ && rm -rf /var/lib/apt/lists/* # Set environment variables for the cache directory (use a writable directory) ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface ENV STREAMLIT_SERVER_PORT=7860 ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 # Create and set the cache directory so the user can write to it RUN mkdir -p /home/user/.cache/huggingface && chown -R user:user /home/user/.cache # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR $HOME/app # Upgrade pip to the latest version to avoid issues with outdated pip RUN pip install --no-cache-dir --upgrade pip # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/app # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Download any necessary assets RUN mkdir -p content ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/data.csv content/data.csv ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/faiss_index.bin content/faiss_index.bin ADD --chown=user https://huggingface.co/datasets/manhteky123/LawVietnamese/resolve/main/vectors.npy content/vectors.npy # Create .streamlit directory and config RUN mkdir -p .streamlit # Health check for Streamlit HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1 # Expose the port the app runs on (change from 5000 to 7860 for Streamlit) EXPOSE 7860 # Define the command to run the Streamlit application CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]