DCA · Question #4
Which one of the following commands will result in the volume being removed automatically once the container has exited?
The correct answer is C. 'docker run --rm -v /foo busybox'. The --rm flag with docker run ensures that both the container and any anonymous volumes it created are automatically removed upon exit.
Question
Which one of the following commands will result in the volume being removed automatically once the container has exited?
Options
- A'docker run --del -v /foo busybox'
- B'docker run --read-only -v /foo busybox'
- C'docker run --rm -v /foo busybox'
- D'docker run --remove -v /foo busybox'
How the community answered
(36 responses)- A3% (1)
- B8% (3)
- C86% (31)
- D3% (1)
Why each option
The `--rm` flag with `docker run` ensures that both the container and any anonymous volumes it created are automatically removed upon exit.
`--del` is not a valid command-line option for the `docker run` command.
`--read-only` makes the container's root filesystem immutable, but it does not control the automatic removal of volumes when the container exits.
The `docker run --rm` command-line option automatically removes the container's file system and any anonymous volumes created by that container once it exits, which is useful for ephemeral workloads.
`--remove` is not a valid command-line option for `docker run`; the correct flag for automatic removal is `--rm`.
Concept tested: Automatic container and volume cleanup
Source: https://docs.docker.com/engine/reference/commandline/run/#clean-up---rm
Topics
Community Discussion
No community discussion yet for this question.