ALYYAN's picture
Update Dockerfile
e547d01 verified
raw
history blame
1.32 kB
# 1. Base Image
FROM python:3.11-slim
# 2. Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV STREAMLIT_SERVER_HEADLESS=true
# --- THE DEFINITIVE FIX IS HERE ---
# Tell Hugging Face to use a cache directory INSIDE the user's home folder
ENV HF_HOME=/home/user/.cache/huggingface
# --- END FIX ---
# 3. Install System Dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git git-lfs libgl1 \
&& rm -rf /var/lib/apt/lists/*
# 4. Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
WORKDIR /home/user/app
# 5. Copy and install Python requirements
COPY --chown=user:user requirements.txt packages.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# 6. Pre-download the model's configuration files (as the correct user)
# This is a small download and ensures the cache directory is created.
RUN python -c "from transformers import AutoImageProcessor; AutoImageProcessor.from_pretrained('google/efficientnet-b2')"
# 7. Copy application code and model artifacts
COPY --chown=user:user . .
RUN git lfs pull
# 8. Expose port and run the app
EXPOSE 8501
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT ["python", "-m", "streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]