Regino commited on
Commit
8faa6ae
Β·
1 Parent(s): 95a3efa

fixed permission

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -18
Dockerfile CHANGED
@@ -1,6 +1,8 @@
1
  FROM python:3.9-slim
2
 
3
- WORKDIR /app
 
 
4
 
5
  # Install system dependencies required by OpenCV and other build tools
6
  # libgl1-mesa-glx: Provides libGL.so.1 (OpenGL library) - THIS IS THE KEY FIX
@@ -16,28 +18,38 @@ RUN apt-get update && apt-get install -y \
16
  libsm6 \
17
  libxrender1 \
18
  ffmpeg \
 
 
19
  # Clean up apt caches to reduce image size
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
- # Copy your requirements.txt file
23
- COPY requirements.txt ./
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # Install Python dependencies from requirements.txt
 
26
  RUN pip3 install --no-cache-dir -r requirements.txt
27
 
28
- # Copy your application source code and assets
29
- # This assumes your project structure looks something like this:
30
- # project_root/
31
- # β”œβ”€β”€ src/
32
- # β”‚ └── streamlit_app.py (your app.py renamed/moved to here)
33
- # β”œβ”€β”€ models/
34
- # β”‚ └── emotion_model_best.h5
35
- # β”œβ”€β”€ cascades/
36
- # β”‚ └── haarcascade_frontalface_default.xml
37
- # β”œβ”€β”€ requirements.txt
38
- # └── Dockerfile
39
- #
40
- # COPY . . copies everything from your project_root into /app in the container.
41
  COPY . .
42
 
43
  EXPOSE 8501
@@ -45,5 +57,5 @@ EXPOSE 8501
45
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
46
 
47
  # Ensure the entrypoint path is correct for your app within the container
48
- # Based on your structure, it's inside 'src/'
49
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
  FROM python:3.9-slim
2
 
3
+ # Define arguments for user ID and group ID (optional, but good for consistency)
4
+ ARG UID=1000
5
+ ARG GID=1000
6
 
7
  # Install system dependencies required by OpenCV and other build tools
8
  # libgl1-mesa-glx: Provides libGL.so.1 (OpenGL library) - THIS IS THE KEY FIX
 
18
  libsm6 \
19
  libxrender1 \
20
  ffmpeg \
21
+ # Add tools for user management
22
+ useradd \
23
  # Clean up apt caches to reduce image size
24
  && rm -rf /var/lib/apt/lists/*
25
 
26
+ # Create a non-root user and group
27
+ # -m: create home directory
28
+ # -u ${UID}: assign specific UID (optional, but good for host volume mounting)
29
+ # -g appgroup: assign to appgroup
30
+ RUN groupadd -g ${GID} appgroup && \
31
+ useradd -m -u ${UID} -g appgroup appuser
32
+
33
+ # Set the HOME environment variable for the new user
34
+ ENV HOME /home/appuser
35
+
36
+ # Set the working directory for the application
37
+ # We'll put it in /app and then change ownership so the non-root user can write to it
38
+ WORKDIR /app
39
 
40
+ # Copy your requirements.txt file and install Python dependencies (as root, for system-wide install)
41
+ COPY requirements.txt .
42
  RUN pip3 install --no-cache-dir -r requirements.txt
43
 
44
+ # Change ownership of the /app directory to the new non-root user
45
+ # This is crucial so that the 'appuser' can read/write in its working directory
46
+ RUN chown -R appuser:appgroup /app
47
+
48
+ # Switch to the non-root user for subsequent commands
49
+ USER appuser
50
+
51
+ # Copy your application source code and assets into the /app directory
52
+ # Now, these files will be owned by 'appuser'
 
 
 
 
53
  COPY . .
54
 
55
  EXPOSE 8501
 
57
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
58
 
59
  # Ensure the entrypoint path is correct for your app within the container
60
+ # Based on your structure, it's inside 'src/' relative to the WORKDIR /app
61
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]