mgbam commited on
Commit
5e1192b
·
verified ·
1 Parent(s): ce859c4

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -2
Dockerfile CHANGED
@@ -1,20 +1,45 @@
1
  FROM python:3.10-slim
2
 
 
 
 
3
  # Install system dependencies including ffmpeg
4
  RUN apt-get update && \
5
  apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
 
6
  rm -rf /var/lib/apt/lists/*
7
 
8
- WORKDIR /app
 
 
 
 
 
 
 
9
 
 
10
  COPY requirements.txt ./
 
 
 
11
  RUN pip install --no-cache-dir --upgrade pip
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
 
14
  COPY . .
15
 
 
 
 
 
 
 
 
16
  # Expose Streamlit's default port
17
  EXPOSE 8501
18
 
19
  # Command to run Streamlit
20
- CMD ["streamlit", "run", "app.py"]
 
 
 
1
  FROM python:3.10-slim
2
 
3
+ # Set environment variables to make Python and Pip output unbuffered (good for logs)
4
+ ENV PYTHONUNBUFFERED=1
5
+
6
  # Install system dependencies including ffmpeg
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
9
+ apt-get clean && \
10
  rm -rf /var/lib/apt/lists/*
11
 
12
+ # Create a non-root user and group
13
+ ARG APP_USER_UID=1000
14
+ ARG APP_USER_GID=1000
15
+ RUN groupadd --gid $APP_USER_GID appgroup && \
16
+ useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
17
+
18
+ # Set the working directory (this will also be appuser's home directory due to --create-home)
19
+ WORKDIR /home/appuser/app
20
 
21
+ # Copy requirements first to leverage Docker cache
22
  COPY requirements.txt ./
23
+
24
+ # Install Python dependencies
25
+ # Ensure pip is up to date, then install requirements
26
  RUN pip install --no-cache-dir --upgrade pip
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
29
+ # Copy the rest of the application code
30
  COPY . .
31
 
32
+ # Change ownership of the app directory to the appuser
33
+ # (WORKDIR is /home/appuser/app, so chown this path)
34
+ RUN chown -R appuser:appgroup /home/appuser/app
35
+
36
+ # Switch to the non-root user
37
+ USER appuser
38
+
39
  # Expose Streamlit's default port
40
  EXPOSE 8501
41
 
42
  # Command to run Streamlit
43
+ # Using server.headless=true is good practice for containers.
44
+ # Streamlit will try to create .streamlit in the user's home dir (/home/appuser)
45
+ CMD ["streamlit", "run", "app.py", "--server.headless=true"]