Aka18 commited on
Commit
c55a9ca
·
verified ·
1 Parent(s): 3727a4e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -12
Dockerfile CHANGED
@@ -1,5 +1,8 @@
1
  FROM python:3.11-slim
2
 
 
 
 
3
  # Set working directory
4
  WORKDIR /app
5
 
@@ -7,6 +10,11 @@ WORKDIR /app
7
  ENV PYTHONUNBUFFERED=1
8
  ENV PYTHONDONTWRITEBYTECODE=1
9
  ENV PYTHONPATH=/app
 
 
 
 
 
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y \
@@ -14,25 +22,23 @@ RUN apt-get update && apt-get install -y \
14
  g++ \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
- # Copy and install requirements first (for better caching)
18
  COPY requirements.txt .
19
- RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
20
  pip install --no-cache-dir -r requirements.txt
21
 
22
- # Copy ALL files (this ensures both .py files are copied)
23
  COPY . .
24
 
25
- # Ensure files have correct permissions
26
- RUN chmod +r *.py
27
-
28
- # Debug: Show what files we have
29
- RUN echo "Files in /app:" && ls -la /app/
30
 
31
- # Create necessary directories
32
- RUN mkdir -p /app/temp /app/analysis_output
33
 
34
  # Expose port
35
  EXPOSE 7860
36
 
37
- # Run Streamlit with explicit file path
38
- CMD ["python", "-m", "streamlit", "run", "/app/app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
 
1
  FROM python:3.11-slim
2
 
3
+ # Create non-root user
4
+ RUN useradd --create-home --shell /bin/bash app_user
5
+
6
  # Set working directory
7
  WORKDIR /app
8
 
 
10
  ENV PYTHONUNBUFFERED=1
11
  ENV PYTHONDONTWRITEBYTECODE=1
12
  ENV PYTHONPATH=/app
13
+ ENV STREAMLIT_SERVER_HEADLESS=true
14
+ ENV STREAMLIT_SERVER_PORT=7860
15
+ ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
16
+ ENV MPLCONFIGDIR=/tmp/matplotlib
17
+ ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
18
 
19
  # Install system dependencies
20
  RUN apt-get update && apt-get install -y \
 
22
  g++ \
23
  && rm -rf /var/lib/apt/lists/*
24
 
25
+ # Copy requirements and install as root
26
  COPY requirements.txt .
27
+ RUN pip install --no-cache-dir --upgrade pip && \
28
  pip install --no-cache-dir -r requirements.txt
29
 
30
+ # Copy application files
31
  COPY . .
32
 
33
+ # Create necessary directories with proper permissions
34
+ RUN mkdir -p /tmp/.streamlit /tmp/matplotlib /app/temp && \
35
+ chown -R app_user:app_user /app /tmp/.streamlit /tmp/matplotlib
 
 
36
 
37
+ # Switch to non-root user
38
+ USER app_user
39
 
40
  # Expose port
41
  EXPOSE 7860
42
 
43
+ # Run Streamlit
44
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]