Dockerfile for Copying Files in Container Image | AZ-300 Exam Solution

Copy Files in Docker Container

Question

Note: This question is part of series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.

After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.

You have a server named Server1 that runs Windows Server 2019. Server1 is a container host.

You are creating a Dockerfile to build a container image.

You need to add a file named File1.txt from Server1 to a folder named C:\Folder1 in the container image.

Solution: You add the following line to the Dockerfile.

Copy-Item File1.txt C:\Folder1\File1.txt

You then build the container image.

Does this meet the goal?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B.

B

Copy-Item is not supported. Copy is the correct command to copy a file to the container image.

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy https://docs.docker.com/engine/reference/builder/

The solution provided meets the goal of adding a file named File1.txt from Server1 to a folder named C:\Folder1 in the container image.

Explanation:

The Dockerfile is a script that contains a set of instructions for building a container image. In this scenario, the Copy-Item command is used to copy the File1.txt from the Server1 host to the C:\Folder1 folder in the container image. This command is executed during the container image build process.

The Copy-Item command is a PowerShell cmdlet that copies an item from one location to another. The first parameter of the cmdlet specifies the source file or folder, while the second parameter specifies the destination file or folder. In this case, the source file is File1.txt located in the current directory, and the destination folder is C:\Folder1\File1.txt within the container image.

Therefore, the provided solution of using the following line in the Dockerfile would successfully copy the File1.txt from Server1 to C:\Folder1 in the container image.

Copy-Item File1.txt C:\Folder1\File1.txt

Hence, the correct answer is A. Yes.