cwadayi commited on
Commit
3b98756
·
verified ·
1 Parent(s): b41cc7b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -1
Dockerfile CHANGED
@@ -2,6 +2,7 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
 
5
  RUN apt-get update && apt-get install -y \
6
  build-essential \
7
  curl \
@@ -9,13 +10,24 @@ RUN apt-get update && apt-get install -y \
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
 
12
  COPY requirements.txt ./
 
 
 
13
  COPY src/ ./src/
14
 
15
- RUN pip3 install -r requirements.txt
 
 
 
 
 
 
16
 
17
  EXPOSE 8501
18
 
19
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
 
21
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Install system dependencies as root
6
  RUN apt-get update && apt-get install -y \
7
  build-essential \
8
  curl \
 
10
  git \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # Copy and install python requirements as root
14
  COPY requirements.txt ./
15
+ RUN pip3 install -r requirements.txt
16
+
17
+ # Copy application code
18
  COPY src/ ./src/
19
 
20
+ # Create a non-root user and its home directory, then change ownership of the app directory.
21
+ # The -m flag is crucial as it creates the home directory (/home/appuser),
22
+ # allowing Streamlit to create its /.streamlit directory there instead of in the root.
23
+ RUN useradd -ms /bin/bash appuser && chown -R appuser:appuser /app
24
+
25
+ # Switch to the non-root user
26
+ USER appuser
27
 
28
  EXPOSE 8501
29
 
30
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
31
 
32
+ # This command will now be executed by 'appuser'
33
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]