tecuts commited on
Commit
4bd2b44
·
verified ·
1 Parent(s): 9b7e41e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -13
Dockerfile CHANGED
@@ -1,24 +1,33 @@
1
- # Use a standard and reliable Hugging Face Python base image
2
  FROM python:3.10-slim
3
 
4
- # Set the working directory inside the container
5
  WORKDIR /code
6
 
7
- # Copy the packages.txt file and install system dependencies (like ffmpeg)
8
- COPY packages.txt packages.txt
9
- RUN apt-get update && apt-get install -y --no-install-recommends $(cat packages.txt) && \
10
- apt-get clean && rm -rf /var/lib/apt/lists/*
11
 
12
- # Copy the requirements.txt file and install Python dependencies
13
- COPY requirements.txt requirements.txt
14
- RUN pip install --no-cache-dir --upgrade pip && \
15
- pip install --no-cache-dir -r requirements.txt
16
 
17
- # Copy the rest of your application code into the container
18
- COPY . /code
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  # Expose the port the app runs on
21
  EXPOSE 7860
22
 
23
- # Command to run the application using uvicorn
24
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use the official Python base image from Docker Hub
2
  FROM python:3.10-slim
3
 
4
+ # Set the working directory
5
  WORKDIR /code
6
 
7
+ # Install system dependencies (like ffmpeg) as the root user
8
+ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && \
9
+ rm -rf /var/lib/apt/lists/*
 
10
 
11
+ # Create a non-root user named 'app' and its home directory
12
+ RUN useradd --create-home app
 
 
13
 
14
+ # Copy all your application files (app.py, requirements.txt, etc.)
15
+ # and set the owner of these files to the 'app' user we just created.
16
+ COPY --chown=app:app . /code
17
+
18
+ # Switch from the 'root' user to the 'app' user
19
+ USER app
20
+
21
+ # Install Python dependencies for the 'app' user only.
22
+ # The --user flag installs packages in the user's home directory.
23
+ RUN pip install --no-cache-dir --user -r /code/requirements.txt
24
+
25
+ # Add the user's local installation directory to the system's PATH.
26
+ # This is crucial so the system can find the 'uvicorn' command.
27
+ ENV PATH="/home/app/.local/bin:${PATH}"
28
 
29
  # Expose the port the app runs on
30
  EXPOSE 7860
31
 
32
+ # Command to run the application. This will now be executed as the 'app' user.
33
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]