Pruning unused resources
Once we have concluded that some clean up is needed Docker provides us with so-called pruning commands. For each resource, such as images, containers, volumes, and networks there exists a prune
command.
Pruning containers
In this section we want to regain unused system resources by pruning containers. Let's start with this command:
$ docker container prune
The preceding command will remove all containers from the system that are not in running
status. Docker will ask for confirmation before deleting the containers that are currently in  exited
or created
status. If you want to skip this confirmation step you can use the -f
(or --force
) flag:
$ docker container prune -f
Under certain circumstances, we might want to remove all containers from our system, even the running ones. We cannot use the prune
command for this. Instead we should use a command, such as the following combined expression:
$ docker container rm -f $(docker container ls -aq)
Please be careful with the preceding...