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?
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.
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
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.
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.
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/
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 :(
We better go with B on this one, its the best answer.....
upvoted 2 times
...
...
...
This section is not available anymore. Please use the main Exam Page.XK0-005 Exam Questions
Log in to ExamTopics
Sign in:
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.
Mistermiyagi
1 week, 3 days agoQubert2
6 months agoDRVision
1 year, 4 months agosalthehash
1 year, 5 months agoAmazing475
1 year, 9 months agoLKRISB
1 year, 11 months agoPOGActual
2 years agolinux_admin
2 years, 2 months agolinux_admin
2 years, 2 months agoKnifeClown1
2 years, 2 months agoCkl22
2 years, 4 months agoNvoid
2 years, 4 months agoMaryamNesa
2 years, 5 months agoTheRealManish
2 years, 4 months agoVeteran903
2 years, 4 months ago