In a multistage Dockerfile, how can you copy a binary from one stage to another?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification 1 Test. Master the core concepts of Kubernetes with multiple-choice questions and detailed explanations. Prepare and boost your confidence for the KCNA certification exam!

Multiple Choice

In a multistage Dockerfile, how can you copy a binary from one stage to another?

Explanation:
In a multistage build, you move artifacts between stages by copying from a previous stage using the COPY instruction with the --from flag. This selects the source stage (either by name or by index) and copies the specified file(s) into the current stage’s filesystem. For example, build the binary in a builder stage, then in the final stage do COPY --from=builder /path/to/binary /usr/local/bin/binary. This keeps the final image small and only includes what you need. Note that just running commands in an earlier stage doesn’t transfer files to later stages. ADD can also use --from, but COPY is the standard choice for straightforward file copies between stages.

In a multistage build, you move artifacts between stages by copying from a previous stage using the COPY instruction with the --from flag. This selects the source stage (either by name or by index) and copies the specified file(s) into the current stage’s filesystem. For example, build the binary in a builder stage, then in the final stage do COPY --from=builder /path/to/binary /usr/local/bin/binary. This keeps the final image small and only includes what you need. Note that just running commands in an earlier stage doesn’t transfer files to later stages. ADD can also use --from, but COPY is the standard choice for straightforward file copies between stages.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy