Deploying Containers on Windows Server 2019: Adding File1.txt to Container Image | AZ-300 Exam Guide

Adding File1.txt to a Docker Container Image

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 File1.txt /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.

A

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 given Dockerfile command COPY File1.txt /Folder1/ copies a file named File1.txt from the build context to a directory named Folder1 in the container. Since the build context is not specified in the command, Docker looks for the file File1.txt in the same directory as the Dockerfile.

However, the requirement is to copy the file from Server1 to the container image. The command specified in the solution does not take into account the source location of the file on Server1.

To meet the requirement, we need to use the Dockerfile command ADD instead of COPY. The ADD command can copy files from the build context or from a remote URL, but it can also copy files from the host machine running the Docker build command. We need to specify the source file path on the host machine and the destination path in the container image.

The correct command to achieve the goal would be:

sql
ADD C:\File1.txt C:\Folder1\

This will copy the file named File1.txt from the C:\ directory on Server1 to the C:\Folder1 directory in the container image.

Therefore, the given solution does not meet the goal, and the correct answer is B. No.