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

Prepare for the Kubernetes Cloud Native Associate (KCNA) Certification test with engaging questions and detailed explanations. Perfect your knowledge and boost your confidence to pass the exam successfully!

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