COPY commands with the --from flag must not reference the alias of the stage in which the COPY appears. Referencing the current FROM alias is logically invalid (a stage cannot copy from itself) and can cause build failures or produce images with missing or incorrect artifacts, which may lead to broken or insecure deployments.
The check examines Dockerfile FROM stages that define an alias (FROM <image> AS <alias>) and flags COPY commands whose --from=<alias> value equals the alias of the current stage. Resources with COPY --from set to the same stage alias will be flagged; fix by removing --from to copy from the current stage or by specifying a different stage name or external image as the --from source.
Secure example copying from a different build stage:
FROMgolang:1.18ASbuilderWORKDIR/appRUN go build -o appFROMalpine:3.16ASruntimeCOPY --from=builder /app/app /usr/local/bin/appCMD["app"]
Compliant Code Examples
FROMgolang:1.7.3ASbuilderWORKDIR/go/src/github.com/foo/href-counter/RUN go get -d -v golang.org/x/net/htmlCOPY app.go .RUNCGO_ENABLED=0GOOS=linux go build -a -installsuffix cgo -o app .# another dockerfileFROMalpine:latestRUN apk --no-cache add ca-certificatesWORKDIR/root/COPY --from=builder /go/src/github.com/foo/href-counter/app .CMD["./app"]
Non-Compliant Code Examples
FROMmyimage:tagasdepCOPY --from=dep /binary /RUN dir c:\
1
2
rulesets:- Dockerfile # Rules to enforce .
맞춤형 데모 요청
Datadog 시작하기
Ask AI
AI-generated responses may be inaccurate. Verify important info.