Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +26 -16
Dockerfile
CHANGED
|
@@ -1,26 +1,36 @@
|
|
| 1 |
-
# Use
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# Set
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
RUN
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
# Run
|
| 26 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use a specific, stable version of the slim image
|
| 2 |
+
FROM python:3.10.13-slim-bullseye
|
| 3 |
|
| 4 |
+
# Set environment variables to prevent interactive prompts during build
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
|
| 8 |
+
# Install git and other system dependencies as root
|
| 9 |
+
RUN apt-get update && apt-get install -y --no-install-recommends git curl && \
|
| 10 |
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Create a non-root user and its home directory
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
WORKDIR /home/user/code
|
| 15 |
|
| 16 |
+
# Set the cache directory for Hugging Face libraries
|
| 17 |
+
# This directory will be created with the correct ownership later
|
| 18 |
+
ENV HF_HOME=/home/user/code/.cache
|
| 19 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 20 |
|
| 21 |
+
# Copy requirements file and install dependencies as the new user
|
| 22 |
+
# First, change ownership of the destination directory
|
| 23 |
+
RUN chown -R user:user /home/user/code
|
| 24 |
+
USER user
|
| 25 |
|
| 26 |
+
COPY --chown=user:user ./requirements.txt .
|
| 27 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 28 |
|
| 29 |
+
# Copy the rest of the application code
|
| 30 |
+
COPY --chown=user:user ./app.py .
|
| 31 |
+
|
| 32 |
+
# Expose the port
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
+
# Run the application
|
| 36 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|