Votes: 0Posted On: Oct 05, 2017 07:32:57
A container is a unit of package that can hold multiple applications with libraries. By doing so, the application will run on any other Linux machine regardless of any customized settings that machine might have.
But as you work with, you may end up accumulating an excessive number of containers that will consume disk space and affect the output.
Hence in order to clean up the containers, you can use the command line to perform this task.
Now before you remove all the containers, you need to make sure to stop the ones that are in use. Else it may throw an error while you try to remove them. Here is how you can stop and remove all the containers at once.
List all the containers so you know the number of containers exists and are to be deleted.
$docker ps -a (Adding the -a flag will show all containers)
As mentioned earlier, you need to stop the container first then remove them all at once.
(Note: -q will provide the IDs of each container to stop and rm commands)
$docker stop $(docker ps -a -q)
$docker rm $(docker ps -a -q)