DCA · Question #5
A container named "analytics" that stores results in a volume called "data" was created. docker run -d --name=analytics -v data:/data app1 How are the results accessed in "data" with another…
The correct answer is B. docker run -d --name=reports --volumes-from=analytics app2. To allow a new container to access an existing volume attached to another container, use the --volumes-from option.
Question
A container named "analytics" that stores results in a volume called "data" was created. docker run -d --name=analytics -v data:/data app1 How are the results accessed in "data" with another container called "app2"?
Options
- Adocker run -d --name=reports --volume=data app2
- Bdocker run -d --name=reports --volumes-from=analytics app2
- Cdocker run -d --name=reports --volume=app1 app2
- Ddocker run -d --name=reports --mount=app1 app2
How the community answered
(21 responses)- A10% (2)
- B81% (17)
- C5% (1)
- D5% (1)
Why each option
To allow a new container to access an existing volume attached to another container, use the `--volumes-from` option.
The command `docker run -d --name=reports --volume=data app2` is incomplete for directly mapping an existing named volume; it requires specifying both the volume name and the container mount path (e.g., `-v data:/data`).
The `docker run --volumes-from=analytics app2` command enables the new container (`app2`) to mount all volumes that were mounted in the specified source container (`analytics`), thereby providing access to the shared 'data' volume.
`app1` is the name of the image used by the first container, not a valid volume name or container name to be referenced with `--volume`.
`--mount=app1` is an incorrect syntax for mounting volumes; `app1` is an image name and not a valid mount source or configuration parameter.
Concept tested: Sharing volumes between Docker containers
Source: https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container---volumes-from
Topics
Community Discussion
No community discussion yet for this question.