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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -14
Dockerfile CHANGED
@@ -1,33 +1,35 @@
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"]
 
1
  # Use the official Python base image from Docker Hub
2
  FROM python:3.10-slim
3
 
4
+ # Install system dependencies (like ffmpeg) as root
 
 
 
5
  RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && \
6
  rm -rf /var/lib/apt/lists/*
7
 
8
+ # Create a non-root user named 'app'
9
  RUN useradd --create-home app
10
 
11
+ # Set the working directory for the application
12
+ WORKDIR /code
13
+
14
+ # Copy all application files from your project into the container's working directory
15
+ COPY . .
16
+
17
+ # Change the ownership of all files and directories within /code.
18
+ # The -R flag is for "recursive," applying this to everything inside /code.
19
+ # THIS IS THE KEY FIX: It gives the 'app' user full control of the directory.
20
+ RUN chown -R app:app /code
21
 
22
  # Switch from the 'root' user to the 'app' user
23
  USER app
24
 
25
+ # Install Python dependencies for the 'app' user
26
+ RUN pip install --no-cache-dir --user -r requirements.txt
 
27
 
28
+ # Add the user's local installation directory to the system's PATH
 
29
  ENV PATH="/home/app/.local/bin:${PATH}"
30
 
31
  # Expose the port the app runs on
32
  EXPOSE 7860
33
 
34
+ # Command to run the application
35
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]