Skip to main content

DL3022: COPY --from should reference a named build stage

Warning Best Practice

Why This Matters

Using numeric references in COPY --from=0 is fragile. If build stages are reordered, added, or removed, the numeric index silently points to the wrong stage. Builds appear correct but copy files from the wrong place, leading to subtle runtime bugs. Named aliases (AS builder) make multi-stage builds self-documenting and refactor-safe.

How to Fix

Use a named alias instead of a numeric stage reference

Before (incorrect)

COPY --from=0 /app/build /usr/share/nginx/html

After (correct)

COPY --from=builder /app/build /usr/share/nginx/html

Rule Details

Rule Code
DL3022
Severity
Warning
Category
Best Practice

Related Rules