BodduSriPavan111 commited on
Commit
ca4b9c6
·
verified ·
1 Parent(s): f4871ef

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -7
Dockerfile CHANGED
@@ -2,14 +2,21 @@ FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
5
- # Create directories and set proper permissions
6
- RUN mkdir -p /tmp/.streamlit /tmp/.config/matplotlib && \
7
- chmod 777 /tmp/.streamlit /tmp/.config/matplotlib
8
 
9
- # Set environment variables for writable directories
 
 
 
 
 
10
  ENV HOME=/tmp
11
  ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
12
  ENV MPLCONFIGDIR=/tmp/.config/matplotlib
 
 
 
13
 
14
  # Install system dependencies
15
  RUN apt-get update && apt-get install -y \
@@ -28,13 +35,27 @@ RUN pip3 install -r requirements.txt
28
 
29
  # Copy source code
30
  COPY src/ ./src/
 
 
 
 
31
 
32
  EXPOSE 8501
33
 
34
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
35
 
36
- # Disable Streamlit usage stats collection and set server config
 
 
 
 
 
 
 
 
 
 
 
37
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", \
38
  "--server.port=8501", \
39
- "--server.address=0.0.0.0", \
40
- "--browser.gatherUsageStats=false"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Create a non-root user
6
+ RUN useradd -m -u 1000 streamlit
 
7
 
8
+ # Create directories with proper ownership
9
+ RUN mkdir -p /tmp/.streamlit /tmp/.config/matplotlib /app/uploads && \
10
+ chown -R streamlit:streamlit /tmp/.streamlit /tmp/.config/matplotlib /app && \
11
+ chmod -R 755 /tmp/.streamlit /tmp/.config/matplotlib /app
12
+
13
+ # Set environment variables
14
  ENV HOME=/tmp
15
  ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
16
  ENV MPLCONFIGDIR=/tmp/.config/matplotlib
17
+ ENV STREAMLIT_SERVER_MAX_UPLOAD_SIZE=200
18
+ ENV STREAMLIT_SERVER_ENABLE_CORS=false
19
+ ENV STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false
20
 
21
  # Install system dependencies
22
  RUN apt-get update && apt-get install -y \
 
35
 
36
  # Copy source code
37
  COPY src/ ./src/
38
+ RUN chown -R streamlit:streamlit /app
39
+
40
+ # Switch to non-root user
41
+ USER streamlit
42
 
43
  EXPOSE 8501
44
 
45
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
46
 
47
+ # Create Streamlit config file
48
+ RUN echo '[server]\n\
49
+ maxUploadSize = 200\n\
50
+ enableCORS = false\n\
51
+ enableXsrfProtection = false\n\
52
+ \n\
53
+ [browser]\n\
54
+ gatherUsageStats = false\n\
55
+ \n\
56
+ [theme]\n\
57
+ base = "light"' > /tmp/.streamlit/config.toml
58
+
59
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", \
60
  "--server.port=8501", \
61
+ "--server.address=0.0.0.0"]