# BiRefNet background removal service — CUDA 12.6 inference image. # torch's +cu126 wheels bundle their own CUDA/cuDNN, so no nvidia/cuda base is # needed; the GPU driver is injected by the nvidia container runtime at run time. FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 \ UV_PROJECT_ENVIRONMENT=/app/.venv \ UV_PYTHON_PREFERENCE=only-system \ UV_COMPILE_BYTECODE=1 \ UV_LINK_MODE=copy \ HF_HOME=/app/hf_cache \ PORT=8000 # uv: fast, reproducible Python + dependency management. COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /uvx /bin/ WORKDIR /app # Install dependencies first so this layer is cached across code changes. # The BuildKit cache mount keeps the uv download cache warm across rebuilds. COPY pyproject.toml uv.lock ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --no-install-project --no-dev --frozen # Application code. COPY src ./src COPY README.md ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --no-dev ENV PATH="/app/.venv/bin:${PATH}" EXPOSE 8000 CMD ["rmbg-as-a-service"]