XK0-005 · Question #416
A Linux administrator found many containers in an exited state. Which of the following commands will allow the administrator to clean up the containers in an exited state?
The correct answer is B. docker rm $(docker ps -aq). docker rm $(docker ps -aq) removes all stopped (exited) containers. The subcommand docker ps -aq lists the IDs of all containers regardless of state using the -a (all) and -q (quiet/IDs only) flags; passing those IDs to docker rm removes them. Running containers cannot be…
Question
A Linux administrator found many containers in an exited state. Which of the following commands will allow the administrator to clean up the containers in an exited state?
Options
- Adocker rm --all
- Bdocker rm $(docker ps -aq)
- Cdocker images prune *
- Ddocker rm --state exited
How the community answered
(17 responses)- A6% (1)
- B82% (14)
- D12% (2)
Explanation
docker rm $(docker ps -aq) removes all stopped (exited) containers. The subcommand docker ps -aq lists the IDs of all containers regardless of state using the -a (all) and -q (quiet/IDs only) flags; passing those IDs to docker rm removes them. Running containers cannot be removed with docker rm unless -f is used, so this command effectively targets exited containers in practice. docker rm --all is not valid Docker syntax. docker images prune * is invalid syntax and targets images, not containers. docker rm --state exited is also not valid Docker syntax.
Topics
Community Discussion
No community discussion yet for this question.