Multiple CMD Instructions Listed
- Query id: 41c195f4-fc31-4a5c-8a1b-90605538d49f
- Query name: Multiple CMD Instructions Listed
- Platform: Dockerfile
- Severity: Medium
- Category: Build Process
- URL: Github
Description¶
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Postitive test num. 1 - dockerfile file
FROM golang:1.7.3
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]
CMD ["./apps"]
Code samples without security vulnerabilities¶
Negative test num. 1 - dockerfile file
FROM golang:1.7.3
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
CMD ["./app"]
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]