FinGPT / Dockerfile
MahekTrivedi's picture
Update Dockerfile
c76bfc7 verified
# Use a Python base image (adjust version as needed, 3.9 is fine as per your logs)
FROM python:3.9-slim
# Set environment variables for cache directories to a writable location
# This resolves PermissionError for /.cache (Hugging Face) and /.config (Matplotlib)
ENV HF_HOME="/tmp/hf_cache"
ENV MPLCONFIGDIR="/tmp/matplotlib"
# Set the working directory in the container
WORKDIR /app
# Install system dependencies
# These are the packages you listed, plus some common ones for ML/data science
RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
# Add any other system dependencies your app might implicitly need
# e.g., if you were doing image processing: libgl1-mesa-glx
&& rm -rf /var/lib/apt/lists/*
# Copy requirements.txt and install Python dependencies
# This is done before copying the rest of the code to leverage Docker's build cache
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
# Create the /tmp/hf_cache and /tmp/matplotlib directories if they don't exist
# and ensure they are writable by the default user.
# The ENV variables above will direct the libraries to use these paths,
# but it's good practice to ensure the directories exist and have correct permissions.
RUN mkdir -p /tmp/hf_cache /tmp/matplotlib && chmod -R 777 /tmp/hf_cache /tmp/matplotlib
# Copy the Streamlit configuration directory
# This is crucial for resolving the PermissionError for Streamlit's own config
COPY .streamlit/ .streamlit/
# Copy your application source code
# Assuming your main Streamlit app is in src/streamlit_app.py
COPY src/ ./src/
# Expose the port Streamlit runs on
EXPOSE 8501
# Healthcheck for the Docker container
# This helps Hugging Face Spaces know when your app is ready
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
# Command to run your Streamlit application
# Ensure this matches the path to your main Streamlit app file
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]