NitinBot002 commited on
Commit
f008752
·
verified ·
1 Parent(s): 1ec6777

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -4
Dockerfile CHANGED
@@ -1,6 +1,12 @@
1
  # Use the official Python 3.9 slim image as the base
2
  FROM python:3.9-slim
3
 
 
 
 
 
 
 
4
  # Set the working directory inside the container
5
  WORKDIR /app
6
 
@@ -8,14 +14,25 @@ WORKDIR /app
8
  COPY requirements.txt requirements.txt
9
 
10
  # Install the Python dependencies
11
- RUN pip install --no-cache-dir -r requirements.txt
 
12
 
13
  # Copy the rest of the application code
14
- COPY . .
 
 
 
 
 
 
 
 
 
15
 
16
  # Expose the port the app runs on (defined by the PORT environment variable or 5000)
17
  EXPOSE 7860
18
 
19
  # Define the command to run the application
20
- # Run the application using Gunicorn
21
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
 
 
1
  # Use the official Python 3.9 slim image as the base
2
  FROM python:3.9-slim
3
 
4
+ # Create a non-root user and group
5
+ # - Create a group named 'appgroup' with GID 1001
6
+ # - Create a user named 'appuser' with UID 1001, assign to 'appgroup', and prevent it from being used for login (-D)
7
+ RUN addgroup --gid 1001 appgroup && \
8
+ adduser --uid 1001 --gid 1001 --disabled-password --gecos '' appuser
9
+
10
  # Set the working directory inside the container
11
  WORKDIR /app
12
 
 
14
  COPY requirements.txt requirements.txt
15
 
16
  # Install the Python dependencies
17
+ # Also install ' dumb-init' which is good practice for handling signals in containers
18
+ RUN pip install --no-cache-dir -r requirements.txt dumb-init
19
 
20
  # Copy the rest of the application code
21
+ # Use --chown to ensure the copied files are owned by appuser:appgroup
22
+ COPY --chown=appuser:appgroup . .
23
+
24
+ # Change ownership of the working directory to appuser:appgroup
25
+ # This ensures that if any build steps created files, or if the volume mount
26
+ # needs to write here, the user has permissions.
27
+ RUN chown -R appuser:appgroup /app
28
+
29
+ # Switch to the non-root user
30
+ USER appuser
31
 
32
  # Expose the port the app runs on (defined by the PORT environment variable or 5000)
33
  EXPOSE 7860
34
 
35
  # Define the command to run the application
36
+ # Use dumb-init to handle PID 1 correctly and forward signals (like SIGTERM from docker stop)
37
+ # Run the application using Gunicorn bound to all interfaces
38
+ CMD ["dumb-init", "gunicorn", "--bind", "0.0.0.0:7860", "app:app"]