Fix Dockerfile for HF Spaces: add user 1000, proper WORKDIR
Browse filesHF Spaces requires containers to run as uid 1000. Previous Dockerfile
ran as root which can cause permission issues during HF's init step.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Dockerfile +11 -6
Dockerfile
CHANGED
|
@@ -1,18 +1,23 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Install dependencies first (layer cache)
|
| 6 |
-
COPY requirements.txt pyproject.toml ./
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
# Copy source
|
| 10 |
-
COPY src/ ./src/
|
| 11 |
-
COPY config/ ./config/
|
| 12 |
-
COPY web/ ./web/
|
| 13 |
|
| 14 |
# Add src/ to Python path (avoids needing setuptools editable install)
|
| 15 |
-
ENV PYTHONPATH=/app/src
|
| 16 |
|
| 17 |
# Hugging Face Spaces requires port 7860
|
| 18 |
ENV PORT=7860
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
+
# HF Spaces runs containers as user 1000
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
USER user
|
| 6 |
+
ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
|
| 7 |
+
|
| 8 |
+
WORKDIR /home/user/app
|
| 9 |
|
| 10 |
# Install dependencies first (layer cache)
|
| 11 |
+
COPY --chown=user requirements.txt pyproject.toml ./
|
| 12 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
|
| 14 |
# Copy source
|
| 15 |
+
COPY --chown=user src/ ./src/
|
| 16 |
+
COPY --chown=user config/ ./config/
|
| 17 |
+
COPY --chown=user web/ ./web/
|
| 18 |
|
| 19 |
# Add src/ to Python path (avoids needing setuptools editable install)
|
| 20 |
+
ENV PYTHONPATH=/home/user/app/src
|
| 21 |
|
| 22 |
# Hugging Face Spaces requires port 7860
|
| 23 |
ENV PORT=7860
|