tueniuu commited on
Commit
4802b69
·
verified ·
1 Parent(s): 3d73988

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -19
Dockerfile CHANGED
@@ -1,31 +1,40 @@
1
- # Use a lightweight Python base image
2
  FROM python:3.9-slim
3
 
4
- # Set the working directory inside the container
 
 
 
 
 
 
 
 
 
 
5
  WORKDIR /app
6
 
7
- # 1. Install System Dependencies (REQUIRED for RDKit & File Parsing)
8
- # - libxrender1, libxext6, libsm6: Required for RDKit Image Drawing
9
- # - libexpat1: Required for XML/SVG parsing
10
  RUN apt-get update && apt-get install -y \
11
- libxrender1 \
12
- libxext6 \
13
- libsm6 \
14
- libexpat1 \
15
  && rm -rf /var/lib/apt/lists/*
 
16
 
17
- # 2. Copy requirements first (from src folder) to cache dependencies
18
- COPY src/requirements.txt .
19
 
20
- # 3. Install Python dependencies
21
- RUN pip install --no-cache-dir --upgrade pip && \
22
- pip install --no-cache-dir -r requirements.txt
23
 
24
- # 4. Copy the rest of the application (src folder content)
25
- COPY src/ .
 
26
 
27
- # 5. Expose port 7860 (Hugging Face Default)
28
  EXPOSE 7860
29
 
30
- # 6. Run the application
31
- CMD ["streamlit", "run", "app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
 
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"]