exam questions

Exam XK0-005 All Questions

View all questions & answers for the XK0-005 exam

Exam XK0-005 topic 1 question 142 discussion

Actual exam question from CompTIA's XK0-005
Question #: 142
Topic #: 1
[All XK0-005 Questions]

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?

  • A. docker rm --all
  • B. docker rm $(docker ps -aq)
  • C. docker images prune *
  • D. docker rm --state exited
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Mistermiyagi
1 week, 3 days ago
Selected Answer: B
For those confused on B or C. The question states containers not images. C would be for images and B would be for containers.
upvoted 1 times
...
Qubert2
6 months ago
In the real world, you would use: docker container prune
upvoted 1 times
...
DRVision
1 year, 4 months ago
Selected Answer: B
I think B has a typo, it should be $(docker ps -aq --filter status=exited) otherwise you removed all the containers
upvoted 4 times
...
salthehash
1 year, 5 months ago
Selected Answer: B
B is the answer
upvoted 1 times
...
Amazing475
1 year, 9 months ago
Selected Answer: B
B is the correct answer
upvoted 2 times
...
LKRISB
1 year, 11 months ago
B. docker rm $(docker ps -aq) Explanation: The command docker ps is used to list running containers. The option -a is used to list all containers, including those in an exited state. The option -q is used to display only the container IDs. The command docker rm is used to remove containers. By using $(docker ps -aq) as a parameter to docker rm, it will remove all containers returned by the docker ps -aq command, which includes containers in an exited state.
upvoted 4 times
...
POGActual
2 years ago
It unfortunately cant be B, as that would remove all container. "You can review the containers on your system with docker ps. Adding the -a flag will show all containers. When you’re sure you want to delete them, you can add the -q flag to supply the IDs to the docker stop and docker rm commands: docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
upvoted 2 times
...
linux_admin
2 years, 2 months ago
Selected Answer: D
The difference between docker rm $(docker ps -aq) and docker rm --state exited is that the first command will remove all containers, regardless of their state, while the second command will only remove containers in an exited state. docker rm $(docker ps -aq) will remove all containers because the docker ps -aq command lists all containers' IDs in quiet mode, and then docker rm removes them. This command will remove all containers, including those that are running, stopped, and exited. docker rm --state exited, on the other hand, only removes containers in an exited state. The --state option is used to specify the state of the containers to be removed, and exited is the state that we want to remove. This command is useful for cleaning up containers that have exited and are no longer needed, freeing up resources and disk space occupied by these containers. In summary, docker rm $(docker ps -aq) removes all containers, while docker rm --state exited removes only containers in an exited state.
upvoted 1 times
linux_admin
2 years, 2 months ago
Of the options given, only option D, docker rm --state exited, would work, but it has a syntax error, as you pointed out. The correct syntax for removing containers in an exited state using Docker is: docker rm $(docker ps -aq --filter "status=exited") This command filters the list of containers to those that are in an exited state, and then removes them.
upvoted 1 times
...
...
KnifeClown1
2 years, 2 months ago
Selected Answer: B
B. docker rm $(docker ps -aq)
upvoted 1 times
...
Ckl22
2 years, 4 months ago
Selected Answer: B
B is the answer "The docker ps command only shows running containers by default. To see all containers, use the -a (or --all) flag" "The example below uses docker ps -q to print the IDs of all containers that have exited (--filter status=exited), and removes those containers with the docker rm command" https://docs.docker.com/engine/reference/commandline/docker/
upvoted 1 times
...
Nvoid
2 years, 4 months ago
Selected Answer: B
going with B, Ref: https://coderwall.com/p/zguz_w/docker-remove-all-exited-containers
upvoted 1 times
...
MaryamNesa
2 years, 5 months ago
Correct answer is B
upvoted 2 times
TheRealManish
2 years, 4 months ago
I'm googling and i see that : B: docker rm $(docker ps -aq) will list and remove all docker containers.. -a is list -q to pass it to the rm command. you need the -f status=exited in that command for it to be valid. As for D, that command doesnt even work at all. so i dont konw what to think. B seems the closest though it's also not right :(
upvoted 1 times
Veteran903
2 years, 4 months ago
We better go with B on this one, its the best answer.....
upvoted 2 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago