Which instruction in a Dockerfile is used to copy files from the host to the container?

Prepare for the Docker Foundations Test. Review essential Docker concepts with multiple choice questions, each with hints and explanations. Ace your exam!

The instruction used to copy files from the host to the container in a Dockerfile is primarily the COPY command. This command enables users to specify the source of the files on the host system and the destination path within the container's filesystem. The key feature of COPY is its straightforward usage, allowing for the direct transfer of files and directories while retaining their original properties.

While ADD is another command that can also be used to copy files from the host to the container, it offers additional functionalities beyond simple copying, such as the ability to unpack compressed files and fetch files from URLs. This makes ADD more versatile but also potentially less predictable in behavior due to its extended capabilities. In most cases where straightforward copying is needed, COPY is favored for clarity and intent.

The other options, such as FROM and FILE, serve different purposes within a Dockerfile. FROM specifies the base image from which the new image is built, and FILE is not a valid Dockerfile instruction at all. Therefore, COPY is the correct answer for the purpose of transferring files from the host to the container.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy