Entz commited on
Commit
c568c6d
·
verified ·
1 Parent(s): fef55f9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -13
Dockerfile CHANGED
@@ -1,28 +1,38 @@
1
- # Dockerfile
2
  FROM python:3.10-slim
3
 
4
- WORKDIR /app
5
- # tells the system to treat /app as the "home" directory, so Streamlit will create /app/.streamlit instead of /.streamlit.
6
- # /app is already writable as root, so no permission issues.
7
- ENV HOME=/app
8
 
 
 
9
 
 
 
 
 
 
 
10
 
11
  # (Optional) system deps if you need them; safe to remove if not needed
 
 
12
  RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
 
13
 
14
- # Install Python deps
15
- COPY requirements.txt /app/
16
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
17
 
18
- # Copy code
19
- COPY . /app
 
 
 
 
20
 
21
  # Do NOT set STREAMLIT_SERVER_PORT here.
22
  # Spaces will inject $PORT at runtime.
23
 
24
-
25
  # Start Streamlit on the port Spaces provides, and bind to 0.0.0.0
26
- # CMD ["bash", "-lc", "streamlit run /app/frontend.py --server.port $PORT --server.address 0.0.0.0"]
27
- # CMD ["sh", "-c", "streamlit run /app/frontend.py --server.port $PORT --server.address 0.0.0.0"]
28
- CMD ["streamlit", "run", "/app/frontend.py", "--server.port", "8501", "--server.address", "0.0.0.0"]
 
1
+ # Use the same base as before
2
  FROM python:3.10-slim
3
 
4
+ # Create a non-root user matching HF Spaces runtime (UID 1000)
5
+ RUN useradd -m -u 1000 user
 
 
6
 
7
+ # Switch to the non-root user
8
+ USER user
9
 
10
+ # Set HOME and PATH for the user
11
+ ENV HOME=/home/user \
12
+ PATH=/home/user/.local/bin:$PATH
13
+
14
+ # Set working directory under HOME
15
+ WORKDIR $HOME/app
16
 
17
  # (Optional) system deps if you need them; safe to remove if not needed
18
+ # Note: Run as root if needed, but here it's fine as user since no installs yet
19
+ USER root
20
  RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
21
+ USER user
22
 
23
+ # Install Python deps as the user
24
+ COPY --chown=user requirements.txt $HOME/app/
25
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
26
 
27
+ # Copy code with correct ownership
28
+ COPY --chown=user . $HOME/app/
29
+
30
+ # Create .streamlit config to disable usage stats (prevents the write attempt causing permission errors)
31
+ RUN mkdir -p $HOME/.streamlit \
32
+ && echo "[browser]\ngatherUsageStats = false" > $HOME/.streamlit/config.toml
33
 
34
  # Do NOT set STREAMLIT_SERVER_PORT here.
35
  # Spaces will inject $PORT at runtime.
36
 
 
37
  # Start Streamlit on the port Spaces provides, and bind to 0.0.0.0
38
+ CMD ["streamlit", "run", "frontend.py", "--server.port", "8501", "--server.address", "0.0.0.0"]