Commit ·
ad53b25
1
Parent(s): b73dbf7
Fix Dockerfile: Install dependencies as root to avoid permission errors
Browse files- Dockerfile +23 -15
Dockerfile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
WORKDIR /
|
| 5 |
|
| 6 |
-
# Install system dependencies
|
| 7 |
-
#
|
| 8 |
USER root
|
| 9 |
RUN apt-get update && apt-get install -y \
|
| 10 |
ffmpeg \
|
|
@@ -12,25 +12,33 @@ RUN apt-get update && apt-get install -y \
|
|
| 12 |
libxext6 \
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
RUN useradd -m -u 1000 user
|
| 17 |
|
| 18 |
-
# Switch to the
|
| 19 |
USER user
|
| 20 |
-
ENV
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
COPY --chown=user . .
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
# Download models
|
| 30 |
-
# This
|
| 31 |
RUN python download_models.py
|
| 32 |
|
| 33 |
-
# Expose the
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
# Command to run the application
|
|
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
| 3 |
+
# Workdir for build steps
|
| 4 |
+
WORKDIR /code
|
| 5 |
|
| 6 |
+
# Install system dependencies (Run as ROOT)
|
| 7 |
+
# This ensures we have permission to install system packages
|
| 8 |
USER root
|
| 9 |
RUN apt-get update && apt-get install -y \
|
| 10 |
ffmpeg \
|
|
|
|
| 12 |
libxext6 \
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
+
# Copy requirements file
|
| 16 |
+
COPY requirements.txt /code/requirements.txt
|
| 17 |
+
|
| 18 |
+
# Install Python dependencies globally (Run as ROOT)
|
| 19 |
+
# Installing as root avoids permission issues with /home/user/.local
|
| 20 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 21 |
+
|
| 22 |
+
# Create a non-root user (Required by Hugging Face Spaces)
|
| 23 |
RUN useradd -m -u 1000 user
|
| 24 |
|
| 25 |
+
# Switch to the non-root user for the application runtime
|
| 26 |
USER user
|
| 27 |
+
ENV HOME=/home/user \
|
| 28 |
+
PATH=/home/user/.local/bin:$PATH
|
| 29 |
|
| 30 |
+
# Set working directory to the user's home/app
|
| 31 |
+
WORKDIR $HOME/app
|
|
|
|
| 32 |
|
| 33 |
+
# Copy the application code (Run as USER)
|
| 34 |
+
# We change ownership to the user so they can read/write if needed
|
| 35 |
+
COPY --chown=user . $HOME/app
|
| 36 |
|
| 37 |
+
# Download models (Run as USER)
|
| 38 |
+
# This ensures models are saved to /home/user/.u2net, which the app can read
|
| 39 |
RUN python download_models.py
|
| 40 |
|
| 41 |
+
# Expose the application port
|
| 42 |
EXPOSE 7860
|
| 43 |
|
| 44 |
# Command to run the application
|