Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +21 -10
Dockerfile
CHANGED
|
@@ -4,20 +4,31 @@ FROM python:3.9-slim
|
|
| 4 |
# Set the working directory in the container
|
| 5 |
WORKDIR /code
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Expose the port the app runs on
|
| 19 |
EXPOSE 8000
|
| 20 |
|
| 21 |
-
# Define the command to run your app
|
| 22 |
-
# This will start the FastAPI server
|
| 23 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
| 4 |
# Set the working directory in the container
|
| 5 |
WORKDIR /code
|
| 6 |
|
| 7 |
+
# ROOT CAUSE FIX: Create a non-root user and grant permissions.
|
| 8 |
+
# This is a best practice for security and avoids permission errors.
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
|
| 12 |
+
# Set environment variables for the new user
|
| 13 |
+
ENV HOME=/home/user
|
| 14 |
+
ENV PATH=/home/user/.local/bin:$PATH
|
| 15 |
+
# Crucially, tell transformers to use a local cache directory we own
|
| 16 |
+
ENV HF_HOME=/code/.cache
|
| 17 |
|
| 18 |
+
# Set the working directory again for the new user context
|
| 19 |
+
WORKDIR $HOME/app
|
| 20 |
+
|
| 21 |
+
# Copy the requirements file and install dependencies
|
| 22 |
+
COPY --chown=user ./requirements.txt $HOME/app/requirements.txt
|
| 23 |
+
RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
|
| 24 |
+
|
| 25 |
+
# Copy the application code, ensuring the 'user' owns the files
|
| 26 |
+
COPY --chown=user ./app $HOME/app/app
|
| 27 |
+
COPY --chown=user ./frontend $HOME/app/frontend
|
| 28 |
+
COPY --chown=user ./main.py $HOME/app/main.py
|
| 29 |
|
| 30 |
# Expose the port the app runs on
|
| 31 |
EXPOSE 8000
|
| 32 |
|
| 33 |
+
# Define the command to run your app
|
|
|
|
| 34 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|