Add File to Docker Container | Azure AZ-300 Exam Preparation

Add File to 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.

ADD File1.txt C:/Folder1/

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 is the correct command to copy a file to the container image. The ADD command can also be used. However, the root directory is specified as '/' and not as

'C:/'.

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

The solution provided in the question is correct and will meet the goal of adding a file named File1.txt from Server1 to a folder named C:\Folder1 in the container image. The Dockerfile command "ADD File1.txt C:/Folder1/" specifies that the File1.txt file should be added to the C:\Folder1 directory in the container image during the build process.

The "ADD" command in a Dockerfile copies files from the build context or local filesystem into the container image being built. In this case, the "File1.txt" file on the Windows Server 2019 host is being added to the container image in the specified directory.

Note that the destination path in the Dockerfile command is specified using forward slashes ("/") instead of backslashes ("") used in Windows. This is because Docker uses Unix-style paths within the container image, even when running on Windows.

Therefore, the correct answer is A. Yes, the provided Dockerfile command will add the File1.txt file to the C:\Folder1 directory in the container image.