Complete dockerfile toolkit with generation and validation capabilities
94
94%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
You are given the following single-stage Dockerfile for a Go application:
FROM golang:1.21
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o server ./cmd/server
RUN apt-get update && apt-get install -y ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 8080
CMD ["/app/server"]Perform Stage 4 (Optimization Analysis) on this Dockerfile.
Identify that this is a compiled language (Go) and that a multi-stage build would eliminate the Go toolchain from the final image.
Propose a multi-stage build using:
build stage (AS build) with golang:1.21 for compilationgcr.io/distroless/base-debian12 or alpine:3.21Estimate the image size reduction that would result from moving to a distroless or Alpine final stage (provide a rough estimate and explain why).
Explain the CI debugging benefit of named build stages (the --target build flag).
Note any security improvements from the distroless approach.
Provide the complete optimised Dockerfile as a code block.