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

Prepare for the KCNA Certification Test. Study with flashcards, multiple-choice questions, and detailed explanations to enhance your understanding of Kubernetes Cloud Native concepts. Ace your 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