There may be a many containers either running or exited in your development machine. You need to clean them up in a regular basis.
To see the list of docker container running locally,
docker ps
But it does not show the excited containers. To see them all use -a
docker ps -a
Finally to delete you need to pass either the id or the name of each container. Wouldn't it be nice to delete them in a loop (its the concept here but we are not using it)? YES indeed it would be. To get only the ids of all the containers we can use -q
switch.
So to get the list of only ids for all the containers we can use,
docker ps -a -q
or
docker ps -aq
To delete we use
docker rm container_id
If we want to loop (again not actual loop but a concept) through all
docker rm $(docker ps -aq)
That's it - your magic command to delete all the running and exited containers in your machine.
This works in Linux (not in Windows).
Top comments (1)
I liked your explanation. Learned few things. Many thanks.