Rolaficus commited on
Commit
7e25f4a
·
verified ·
1 Parent(s): 3ad445f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -8
Dockerfile CHANGED
@@ -1,22 +1,40 @@
1
- # Use Python 3.9
2
- FROM python:3.9
 
 
 
 
 
3
 
4
  # Set working directory
5
  WORKDIR /code
6
 
7
- # Copy requirements and install
 
 
 
 
 
 
 
 
 
 
 
8
  COPY ./requirements.txt /code/requirements.txt
9
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
10
 
11
- # Copy the app
12
- COPY . .
 
13
 
14
- # Create a non-root user (required by HF Spaces)
15
- RUN useradd -m -u 1000 user
16
  USER user
 
 
17
  ENV HOME=/home/user \
18
  PATH=/home/user/.local/bin:$PATH
19
 
20
  # Run the app
21
- # CHANGED: "main:app" matches the filename main.py
22
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use the slim version of Python 3.9 (Debian Bullseye)
2
+ # This is often more stable for networking in restricted environments
3
+ FROM python:3.9-slim-bullseye
4
+
5
+ # Set environment variables to prevent Python from writing .pyc files
6
+ ENV PYTHONDONTWRITEBYTECODE=1 \
7
+ PYTHONUNBUFFERED=1
8
 
9
  # Set working directory
10
  WORKDIR /code
11
 
12
+ # Install system dependencies (needed for some networking libraries)
13
+ # We install ca-certificates explicitly to ensure HTTPS works
14
+ RUN apt-get update \
15
+ && apt-get install -y --no-install-recommends \
16
+ ca-certificates \
17
+ netbase \
18
+ && rm -rf /var/lib/apt/lists/*
19
+
20
+ # Create a non-root user (required by HF Spaces)
21
+ RUN useradd -m -u 1000 user
22
+
23
+ # Copy requirements first (for caching)
24
  COPY ./requirements.txt /code/requirements.txt
25
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
26
 
27
+ # Copy the app files AND change ownership to the 'user'
28
+ # This is critical: standard COPY makes files owned by root, which can cause permission errors
29
+ COPY --chown=user . /code
30
 
31
+ # Switch to the non-root user
 
32
  USER user
33
+
34
+ # Set home environment
35
  ENV HOME=/home/user \
36
  PATH=/home/user/.local/bin:$PATH
37
 
38
  # Run the app
39
+ # Using 0.0.0.0 is required for Docker networking
40
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]