sandbox338 commited on
Commit
b0c3b32
·
verified ·
1 Parent(s): 245fd12

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -7
Dockerfile CHANGED
@@ -2,11 +2,12 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
5
- # Set HOME to a writable location
6
  ENV HOME=/app
7
- ENV MPLCONFIGDIR=/app/.config/matplotlib
8
- ENV TORCH_HOME=/app/.torch
9
- ENV STREAMLIT_HOME=/app/.streamlit
 
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y \
@@ -25,8 +26,9 @@ RUN apt-get update && apt-get install -y \
25
  zlib1g-dev \
26
  && rm -rf /var/lib/apt/lists/*
27
 
28
- # Create required writable folders
29
- RUN mkdir -p /app/.torch /app/.streamlit /app/.config/matplotlib
 
30
 
31
  # Copy project files
32
  COPY requirements.txt ./
@@ -39,8 +41,23 @@ RUN pip install --upgrade pip && \
39
  pip install torchvision==0.15.2 && \
40
  pip install 'git+https://github.com/facebookresearch/detectron2.git'
41
 
 
 
 
 
42
  EXPOSE 8501
43
 
 
44
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
45
 
46
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
5
+ # Set up environment variables for writable directories
6
  ENV HOME=/app
7
+ ENV MPLCONFIGDIR=/tmp/.matplotlib
8
+ ENV TORCH_HOME=/tmp/.torch
9
+ ENV STREAMLIT_HOME=/tmp/.streamlit
10
+ ENV PYTHONPATH=$PYTHONPATH:/app
11
 
12
  # Install system dependencies
13
  RUN apt-get update && apt-get install -y \
 
26
  zlib1g-dev \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
+ # Create temporary directories with proper permissions
30
+ RUN mkdir -p /tmp/.torch /tmp/.streamlit /tmp/.matplotlib \
31
+ && chmod 777 /tmp/.torch /tmp/.streamlit /tmp/.matplotlib
32
 
33
  # Copy project files
34
  COPY requirements.txt ./
 
41
  pip install torchvision==0.15.2 && \
42
  pip install 'git+https://github.com/facebookresearch/detectron2.git'
43
 
44
+ # Set proper ownership for application files
45
+ RUN chown -R 1000:1000 /app
46
+
47
+ # Expose Streamlit port
48
  EXPOSE 8501
49
 
50
+ # Add a healthcheck
51
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
52
 
53
+ # Run as non-root user for better security
54
+ USER 1000
55
+
56
+ # Set up Streamlit configuration
57
+ RUN mkdir -p /tmp/.streamlit && echo '\
58
+ [general]\n\
59
+ email = ""\n\
60
+ ' > /tmp/.streamlit/credentials.toml
61
+
62
+ # Command to run the app
63
+ ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]