Consider the following excerpt from a Dockerfile used to containerize a Go microservice:
FROM golang:1.22-alpine AS builder
WORKDIR /src
COPY . .
RUN go build -o /app/service
FROM scratch
COPY --from=builder /app/service /service
ENTRYPOINT ["/service"]
What specific effect does the second FROM scratch instruction have on the image-build process?
It merges the filesystem layers from the builder stage with those of scratch, producing an image that contains both the Go toolchain and the compiled binary.
It instructs Docker to pull the scratch image from Docker Hub; if the image cannot be pulled the build fails.
It reuses the builder stage as the base of the final image but strips its tag, keeping all previously installed packages and tools.
It starts a new build stage with an empty filesystem, so none of the layers from the golang:1.22-alpine stage are included unless files are explicitly copied with --from.
Each FROM line in a multi-stage Dockerfile begins a new build stage. When the second stage uses the reserved scratch image, Docker starts with an entirely empty filesystem. All layers, environment variables, and files created in the builder stage are left behind and are not carried into the new stage. Only objects that are explicitly copied with a COPY --from=<stage> (such as the compiled binary) become part of the final image. The other options are incorrect because Docker does not merge earlier layers, does not pull an actual scratch image (it is a keyword, not a real image), and does not automatically reuse the previous stage's filesystem.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the 'scratch' image in Docker?
Open an interactive chat with Bash
How does `COPY --from` work in a multi-stage Docker build?
Open an interactive chat with Bash
Why use multi-stage builds in Docker?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access