In a multistage Dockerfile, which option is used with the COPY instruction to copy artifacts from a previous stage?

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, which option is used with the COPY instruction to copy artifacts from a previous stage?

Explanation:
In multistage Docker builds, you pull artifacts from an earlier stage into a later one using the COPY instruction with the --from flag. The value after --from identifies which stage to copy from, either by the stage name you gave with AS or by its index. For example, you might build in a stage named builder and then copy a binary from that stage into the final image: COPY --from=builder /path/to/binary /usr/local/bin/binary. This lets you keep the final image slim by only including what you need. The other options aren’t used to copy from previous stages: --as is used when naming a stage (FROM image AS stage_name) rather than for COPY, and --reference and --stage aren’t valid COPY flags for selecting a previous stage.

In multistage Docker builds, you pull artifacts from an earlier stage into a later one using the COPY instruction with the --from flag. The value after --from identifies which stage to copy from, either by the stage name you gave with AS or by its index. For example, you might build in a stage named builder and then copy a binary from that stage into the final image: COPY --from=builder /path/to/binary /usr/local/bin/binary. This lets you keep the final image slim by only including what you need.

The other options aren’t used to copy from previous stages: --as is used when naming a stage (FROM image AS stage_name) rather than for COPY, and --reference and --stage aren’t valid COPY flags for selecting a previous stage.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy