DCA · Question #1
Which of the following commands wifi automatically create a volume when a container is started?
The correct answer is A. 'docker container run --name nginxtest --volumes=/app nginx'. To automatically create an anonymous volume when starting a container, the docker container run command should use the -v /container/path or --volumes=/container/path syntax.
Question
Which of the following commands wifi automatically create a volume when a container is started?
Options
- A'docker container run --name nginxtest --volumes=/app nginx'
- B'docker container run --name nginxtest -v /app:mount nginx'
- C'docker container run --name nginxtest --volumes myvol:/app:new nginx'
- D'docker container run --name nginxtest -v myvol:/app nginx'
How the community answered
(36 responses)- A75% (27)
- B3% (1)
- C8% (3)
- D14% (5)
Why each option
To automatically create an anonymous volume when starting a container, the `docker container run` command should use the `-v /container/path` or `--volumes=/container/path` syntax.
The `docker container run --volumes=/app` command, equivalent to `-v /app`, instructs Docker to automatically provision and manage a new anonymous volume, without a user-defined name, and mount it inside the container at the specified path `/app`.
This command specifies a bind mount, which maps a host directory (`/app`) to a container directory (`mount`), rather than creating a Docker-managed volume.
The syntax `--volumes myvol:/app:new` is incorrect; the `:new` option is not a valid part of the volume flag syntax for creating or mounting a volume.
This command uses a named volume (`myvol`); while Docker creates `myvol` if it doesn't exist, it is explicitly named by the user, distinguishing it from the automatically named anonymous volume in option A.
Concept tested: Anonymous volume creation
Source: https://docs.docker.com/storage/volumes/#create-and-manage-volumes
Topics
Community Discussion
No community discussion yet for this question.