NavyDevilDoc commited on
Commit
ff85e7e
·
verified ·
1 Parent(s): 7e2cb5d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -12
Dockerfile CHANGED
@@ -1,31 +1,34 @@
1
  # Use an official lightweight Python image.
2
- # 3.11 is stable and faster than previous versions.
3
  FROM python:3.11-slim
4
 
5
  # Set environment variables
6
- # PYTHONDONTWRITEBYTECODE: Prevents Python from writing pyc files to disc
7
- # PYTHONUNBUFFERED: Prevents Python from buffering stdout and stderr
8
  ENV PYTHONDONTWRITEBYTECODE=1
9
  ENV PYTHONUNBUFFERED=1
10
 
 
 
 
 
 
11
  # Set the working directory in the container
12
  WORKDIR /app
13
 
14
  # Copy the requirements file first to leverage Docker cache
15
- COPY requirements.txt .
 
16
 
17
  # Install dependencies
18
- RUN pip install --no-cache-dir -r requirements.txt
19
 
20
  # Copy the rest of the application code
21
- COPY . .
22
 
23
- # Expose the port Streamlit runs on
24
- EXPOSE 8501
25
 
26
- # Healthcheck to ensure the container is responsive
27
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
28
 
29
  # Command to run the application
30
- # server.address=0.0.0.0 is crucial for Docker networking
31
- CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
 
1
  # Use an official lightweight Python image.
 
2
  FROM python:3.11-slim
3
 
4
  # Set environment variables
 
 
5
  ENV PYTHONDONTWRITEBYTECODE=1
6
  ENV PYTHONUNBUFFERED=1
7
 
8
+ # Create a non-root user (Recommended for HF Spaces security permissions)
9
+ RUN useradd -m -u 1000 user
10
+ USER user
11
+ ENV PATH="/home/user/.local/bin:$PATH"
12
+
13
  # Set the working directory in the container
14
  WORKDIR /app
15
 
16
  # Copy the requirements file first to leverage Docker cache
17
+ # Note the --chown flag to ensure the non-root user owns the files
18
+ COPY --chown=user ./requirements.txt requirements.txt
19
 
20
  # Install dependencies
21
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
22
 
23
  # Copy the rest of the application code
24
+ COPY --chown=user . /app
25
 
26
+ # Expose the port strictly required by Hugging Face Spaces
27
+ EXPOSE 7860
28
 
29
+ # Healthcheck updated to check the correct port
30
+ HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1
31
 
32
  # Command to run the application
33
+ # Note the addition of --server.port=7860
34
+ CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.port=7860"]