Update Dockerfile
Browse files- Dockerfile +22 -13
Dockerfile
CHANGED
|
@@ -1,24 +1,33 @@
|
|
| 1 |
-
# Use
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# Set the working directory
|
| 5 |
WORKDIR /code
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
RUN pip install --no-cache-dir --upgrade pip && \
|
| 15 |
-
pip install --no-cache-dir -r requirements.txt
|
| 16 |
|
| 17 |
-
# Copy
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Expose the port the app runs on
|
| 21 |
EXPOSE 7860
|
| 22 |
|
| 23 |
-
# Command to run the application
|
| 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"]
|