nerdexam
Docker

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.

Submitted by parkjh· Apr 18, 2026Storage and Volumes

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)
  • A
    3% (1)
  • B
    8% (3)
  • C
    86% (31)
  • D
    3% (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.

A'docker run --del -v /foo busybox'

`--del` is not a valid command-line option for the `docker run` command.

B'docker run --read-only -v /foo busybox'

`--read-only` makes the container's root filesystem immutable, but it does not control the automatic removal of volumes when the container exits.

C'docker run --rm -v /foo busybox'Correct

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.

D'docker run --remove -v /foo busybox'

`--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

#Docker run command#Volume Management#Container Lifecycle#Anonymous Volumes

Community Discussion

No community discussion yet for this question.

Full DCA Practice