nerdexam
CompTIA

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…

System Management

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)
  • A
    6% (1)
  • B
    82% (14)
  • D
    12% (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

#Docker#Container Management#Linux CLI#System Cleanup

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice