FROM nvcr.io/nvidia/pytorch:26.03-py3 # --------------------------------------------------------------------------- # Install uv # --------------------------------------------------------------------------- COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /workspace # --------------------------------------------------------------------------- # Virtual environment # # --system-site-packages makes the venv inherit every package already # installed in the NVIDIA base image, including torch, torchvision, and the # matching CUDA libraries. uv will not reinstall those packages (they are # declared in [tool.uv] exclude-dependencies), so the base-image builds are # left untouched. # --------------------------------------------------------------------------- RUN uv venv /opt/venv --system-site-packages ENV VIRTUAL_ENV=/opt/venv ENV PATH="/opt/venv/bin:$PATH" # --------------------------------------------------------------------------- # Layer 1 — install dependencies (not the project itself) # # Only pyproject.toml is present at this point, so Docker re-runs this step # only when the dependency list changes, not when source files change. # --------------------------------------------------------------------------- COPY pyproject.toml . RUN uv sync --no-install-project # --------------------------------------------------------------------------- # Layer 2 — copy source and finish # # With package = false in pyproject.toml there is nothing extra to install; # the second sync is a fast no-op that confirms the environment is complete. # --------------------------------------------------------------------------- COPY . . RUN uv sync