InventorsHub commited on
Commit
21439bf
·
verified ·
1 Parent(s): 12549e0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +39 -27
Dockerfile CHANGED
@@ -1,27 +1,39 @@
1
- # Use a slim Python base image
2
- FROM python:3.10-slim
3
-
4
- # Create a non-root user (UID 1000) to match Spaces runtime
5
- RUN useradd -m -u 1000 user
6
-
7
- # Switch to the non-root user
8
- USER user
9
- ENV HOME=/home/user \
10
- PATH=/home/user/.local/bin:$PATH
11
-
12
- # Set the working directory to the user's home
13
- WORKDIR /home/user/app
14
-
15
- # Copy and install Python dependencies
16
- COPY --chown=user requirements.txt ./
17
- RUN pip install --upgrade pip && \
18
- pip install --no-cache-dir -r requirements.txt
19
-
20
- # Copy the rest of the application code
21
- COPY --chown=user . ./
22
-
23
- # Expose the port defined in README.md (app_port: 7860)
24
- EXPOSE 7860
25
-
26
- # Launch the Gradio app on 0.0.0.0 so it's reachable externally
27
- CMD ["python", "app.py", "--server_port", "7860", "--server_name", "0.0.0.0"]
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a slim Python base image
2
+ FROM python:3.10-slim
3
+
4
+ # Create a non-root user (UID 1000) to match Spaces runtime
5
+ RUN useradd -m -u 1000 user
6
+
7
+ # Set environment vars for the non-root user
8
+ ENV HOME=/home/user \
9
+ PATH=/home/user/.local/bin:$PATH
10
+
11
+ # Set working directory
12
+ WORKDIR /home/user/app
13
+
14
+ # Copy only requirements first (for layer caching)
15
+ COPY --chown=user requirements.txt ./
16
+
17
+ # Switch to root to install system build dependencies
18
+ USER root
19
+ RUN apt-get update \
20
+ && apt-get install -y --no-install-recommends \
21
+ build-essential \
22
+ cmake \
23
+ python3-dev \
24
+ libffi-dev \
25
+ && rm -rf /var/lib/apt/lists/*
26
+
27
+ # Switch back to non-root user for pip install
28
+ USER user
29
+ RUN pip install --upgrade pip \
30
+ && pip install --no-cache-dir -r requirements.txt
31
+
32
+ # Copy the rest of your application code
33
+ COPY --chown=user . ./
34
+
35
+ # Expose the port your app runs on
36
+ EXPOSE 7860
37
+
38
+ # Launch the Gradio app on 0.0.0.0 so it's reachable externally
39
+ CMD ["python", "app.py", "--server_port", "7860", "--server_name", "0.0.0.0"]