Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +28 -19
Dockerfile
CHANGED
|
@@ -1,31 +1,40 @@
|
|
| 1 |
-
# Use
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
# Set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
# - libexpat1: Required for XML/SVG parsing
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
libsm6 \
|
| 14 |
-
libexpat1 \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
COPY
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
RUN pip install --
|
| 22 |
-
pip install
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
EXPOSE 7860
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
CMD ["streamlit", "run", "app.py", "--server.
|
|
|
|
| 1 |
+
# 1. Use an official lightweight Python image
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# 2. Set environment variables to prevent Python from buffering stdout/stderr
|
| 5 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 6 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PIP_NO_CACHE_DIR=1
|
| 8 |
+
|
| 9 |
+
# 3. Create a non-root user (Security Best Practice for HF Spaces)
|
| 10 |
+
RUN useradd -m -u 1000 user
|
| 11 |
+
USER user
|
| 12 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 13 |
+
|
| 14 |
+
# 4. Set the working directory
|
| 15 |
WORKDIR /app
|
| 16 |
|
| 17 |
+
# 5. Install system dependencies (Git is often needed for cloning repos)
|
| 18 |
+
USER root
|
|
|
|
| 19 |
RUN apt-get update && apt-get install -y \
|
| 20 |
+
git \
|
| 21 |
+
build-essential \
|
|
|
|
|
|
|
| 22 |
&& rm -rf /var/lib/apt/lists/*
|
| 23 |
+
USER user
|
| 24 |
|
| 25 |
+
# 6. Copy requirements first (to leverage Docker caching)
|
| 26 |
+
COPY --chown=user requirements.txt ./
|
| 27 |
|
| 28 |
+
# 7. Install Python dependencies
|
| 29 |
+
RUN pip install --upgrade pip && \
|
| 30 |
+
pip install -r requirements.txt
|
| 31 |
|
| 32 |
+
# 8. Copy the rest of the application files
|
| 33 |
+
# This includes app.py and your .pkl model files
|
| 34 |
+
COPY --chown=user . .
|
| 35 |
|
| 36 |
+
# 9. Expose the port Hugging Face Spaces expects (7860)
|
| 37 |
EXPOSE 7860
|
| 38 |
|
| 39 |
+
# 10. Run the Streamlit app on port 7860
|
| 40 |
+
CMD ["streamlit", "run", "app.py", "--server.address", "0.0.0.0", "--server.port", "7860"]
|