Which option automatically removes the container when it exits?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification. Prepare with flashcards and multiple choice questions. Ensure success with detailed explanations. Ready for your exam!

Multiple Choice

Which option automatically removes the container when it exits?

Explanation:
Automatically removing a container after it exits is controlled by the long form flag --rm used with the run command. This tells Docker to delete the container’s instance and its temporary filesystem as soon as the main process finishes, so you don’t end up with a pile of stopped containers. The short form -rm isn’t a valid flag, and the other options don’t apply here. For example, docker run --rm alpine echo hi runs the command and then cleans up the container immediately after it exits. Note that while the container is removed, any named volumes persist unless you remove them separately; anonymous volumes created for that container can be cleaned up with the container.

Automatically removing a container after it exits is controlled by the long form flag --rm used with the run command. This tells Docker to delete the container’s instance and its temporary filesystem as soon as the main process finishes, so you don’t end up with a pile of stopped containers. The short form -rm isn’t a valid flag, and the other options don’t apply here.

For example, docker run --rm alpine echo hi runs the command and then cleans up the container immediately after it exits. Note that while the container is removed, any named volumes persist unless you remove them separately; anonymous volumes created for that container can be cleaned up with the container.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy