Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +17 -16
Dockerfile
CHANGED
|
@@ -1,36 +1,37 @@
|
|
| 1 |
# Use an official Python runtime as a parent image.
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
WORKDIR /code
|
| 6 |
-
|
| 7 |
-
# --- NEW: Set up a non-root user ---
|
| 8 |
-
# Create a user 'user' with user ID 1000
|
| 9 |
RUN useradd -m -u 1000 user
|
| 10 |
-
|
|
|
|
| 11 |
USER user
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
# Set the home directory for the user
|
| 15 |
ENV HOME=/home/user
|
| 16 |
-
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
ENV TRANSFORMERS_CACHE=$HOME/.cache
|
| 19 |
|
| 20 |
-
# Set the working directory
|
| 21 |
WORKDIR $HOME/app
|
| 22 |
|
| 23 |
-
# Copy
|
| 24 |
COPY --chown=user:user ./requirements.txt .
|
| 25 |
|
| 26 |
-
# Install
|
| 27 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 28 |
|
| 29 |
-
# Copy
|
| 30 |
COPY --chown=user:user ./app.py .
|
| 31 |
|
| 32 |
-
#
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
-
# Command to run your app.
|
| 36 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
# Use an official Python runtime as a parent image.
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Create a dedicated, non-root user for security.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
RUN useradd -m -u 1000 user
|
| 6 |
+
|
| 7 |
+
# Switch to this new user.
|
| 8 |
USER user
|
| 9 |
|
| 10 |
+
# Set environment variables that will be available to the 'user'.
|
|
|
|
| 11 |
ENV HOME=/home/user
|
| 12 |
+
|
| 13 |
+
# --- THIS IS THE FIX ---
|
| 14 |
+
# Add the user's local binary directory to the system's PATH.
|
| 15 |
+
# This ensures that executables installed by pip (like uvicorn) can be found.
|
| 16 |
+
ENV PATH=$HOME/.local/bin:$PATH
|
| 17 |
+
|
| 18 |
+
# Set the cache directory for transformers.
|
| 19 |
ENV TRANSFORMERS_CACHE=$HOME/.cache
|
| 20 |
|
| 21 |
+
# Set the working directory for the application.
|
| 22 |
WORKDIR $HOME/app
|
| 23 |
|
| 24 |
+
# Copy and own the requirements file.
|
| 25 |
COPY --chown=user:user ./requirements.txt .
|
| 26 |
|
| 27 |
+
# Install Python dependencies.
|
| 28 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 29 |
|
| 30 |
+
# Copy and own the application file.
|
| 31 |
COPY --chown=user:user ./app.py .
|
| 32 |
|
| 33 |
+
# Expose the port the app will run on.
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
+
# Command to run your app. Now 'uvicorn' can be found in the PATH.
|
| 37 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|