Skip to main content
GPU hardware is not available during docker build; runtime GPU queries in RUN will fail or return misleading results.

Description

Detects RUN instructions that query GPU hardware at build time. GPU devices are not attached during a normal docker build, so commands like nvidia-smi and runtime framework checks like torch.cuda.is_available() will either fail outright or return misleading results (e.g., zero devices, False). This rule does not fire on CMD or ENTRYPOINT, where GPU queries are expected to run at container startup.

Why this matters

  • Build failuresnvidia-smi will exit non-zero when no GPU is present, breaking the build
  • Silent wrong resultstorch.cuda.is_available() returns False at build time, which can cause downstream logic to skip GPU code paths or produce incorrect configuration
  • Misleading smoke tests — a passing build does not mean GPU support works; the check must happen at runtime
  • Official guidance — Hugging Face explicitly warns that GPU hardware is not available during docker build

Detected patterns

GPU query commands

Python/ML framework runtime checks

Examples

Violation

No violation

Configuration

This rule has no rule-specific options.

References