MB-IDK's picture
Rename dockerfile.txt to Dockerfile
eadb935 verified
Raw
History Blame Contribute Delete
2.27 kB
# ── Base ───────────────────────────────────────────────────────────────────────
# slim image keeps the layer small; HF free tier is CPU-only
FROM python:3.11-slim
# ── System deps ────────────────────────────────────────────────────────────────
# libgl1 + libglib2.0-0 are required by OpenCV (pulled in by ultralytics)
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# ── HF Spaces user (uid 1000) ──────────────────────────────────────────────────
# Spaces runs as a non-root user; pre-create it so chown works
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH="/home/user/.local/bin:$PATH" \
PYTHONUNBUFFERED=1 \
# tell HF hub to cache inside the writable home dir
HF_HOME=/home/user/.cache/huggingface \
# disable YOLO's attempt to write analytics / config to /root
YOLO_CONFIG_DIR=/home/user/.config/ultralytics
WORKDIR /home/user/app
# ── Python deps ────────────────────────────────────────────────────────────────
# Copy requirements first so Docker can cache this layer
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# ── App code ───────────────────────────────────────────────────────────────────
COPY --chown=user . .
# ── Runtime ────────────────────────────────────────────────────────────────────
EXPOSE 7860
CMD ["python", "app.py"]