mgbam commited on
Commit
648c0bc
·
verified ·
1 Parent(s): 150c011

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +52 -24
Dockerfile CHANGED
@@ -1,30 +1,58 @@
1
- # Use the official Python 3.10 slim image as the base
2
  FROM python:3.10-slim
3
 
4
- # Set environment variables to ensure consistent behavior
5
  ENV PYTHONUNBUFFERED=1 \
6
- STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
7
- STREAMLIT_SERVER_HEADLESS=true \
8
- STREAMLIT_HOME=/tmp/.streamlit
 
9
 
10
- # Create the .streamlit directory with appropriate permissions
11
- RUN mkdir -p $STREAMLIT_HOME && chmod -R 755 $STREAMLIT_HOME
12
-
13
- # Set the working directory in the container
14
  WORKDIR /app
15
-
16
- # Copy only the requirements file first to leverage Docker cache
17
- COPY requirements.txt .
18
-
19
- # Install Python dependencies
20
- RUN pip install --no-cache-dir --upgrade pip \
21
- && pip install --no-cache-dir -r requirements.txt
22
-
23
- # Copy the rest of the application code
24
- COPY . .
25
-
26
- # Expose the port Streamlit will run on
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  EXPOSE 8501
28
-
29
- # Define the command to run the Streamlit app
30
- CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # Use a stable slim Python base image
2
  FROM python:3.10-slim
3
 
4
+ # Set environment variables
5
  ENV PYTHONUNBUFFERED=1 \
6
+ LANG=C.UTF-8 \
7
+ LC_ALL=C.UTF-8 \
8
+ PIP_NO_CACHE_DIR=1 \
9
+ STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
10
 
11
+ # Create working directory and Streamlit config path with correct permissions
 
 
 
12
  WORKDIR /app
13
+ RUN useradd -m -u 1000 appuser && \
14
+ mkdir -p /home/appuser/.streamlit && \
15
+ chown -R appuser /home/appuser && \
16
+ apt-get update && apt-get install -y \
17
+ build-essential \
18
+ curl \
19
+ git \
20
+ libglib2.0-0 \
21
+ libsm6 \
22
+ libxrender1 \
23
+ libxext6 \
24
+ libxml2 \
25
+ libxslt1-dev \
26
+ libffi-dev \
27
+ libbz2-dev \
28
+ liblzma-dev \
29
+ zlib1g-dev \
30
+ libjpeg-dev \
31
+ libpq-dev \
32
+ gcc \
33
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
34
+
35
+ # Switch to non-root user for safety
36
+ USER appuser
37
+
38
+ # Copy requirement files and install dependencies
39
+ COPY --chown=appuser:appuser requirements.txt /app/
40
+ RUN pip install --upgrade pip && pip install -r requirements.txt
41
+
42
+ # Copy rest of the application code
43
+ COPY --chown=appuser:appuser . /app
44
+
45
+ # Streamlit config
46
+ RUN echo "\
47
+ [server]\n\
48
+ headless = true\n\
49
+ port = 8501\n\
50
+ enableCORS = false\n\
51
+ \n\
52
+ [theme]\n\
53
+ base = 'light'\n\
54
+ " > /home/appuser/.streamlit/config.toml
55
+
56
+ # Default command
57
  EXPOSE 8501
58
+ CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0"]