What command would mount a directory from the host to a container?

Prepare for the Docker Certified Associate test with our comprehensive quizzes that include key questions and detailed explanations. Ace your certification!

The correct approach for mounting a directory from the host to a Docker container is indeed the option that utilizes the --mount flag. When you use docker run --mount source=/my/path,destination=/tmp nginx, you are specifying that you want to mount a source directory from the host, /my/path, to a specified destination within the container, /tmp, while running the nginx image. This method provides a clear and structured way to define the mount parameters, including the source and destination of the filesystem being shared between the host and the container.

Using the --mount flag in this manner also allows for additional options such as specifying the type of mount (volume, bind, etc.) and giving more robust control over the mounting process compared to other methods like -v which does not provide the same flexibility or structure. This makes it the recommended approach for defining mounts in modern Docker practices.

The other choices presented do not correctly utilize the syntax or commands to achieve the desired outcome of mounting a directory. For example, simply using docker mount is not a recognized command in Docker's CLI. The attempt to use -m is incorrect as there is no such option for running a container with a

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy