Images, containers and networks can be removed using the prune command. The prune operation will only remove images/containers/networks that are not currently running.
All of the below examples will prompt for user input before making changes. To skip the prompt add --force.
Prune containers:
docker container prune
Prune images:
docker image prune
Prune networks:
docker network prune
Prune volumes;
docker volume prune
To prune everything in a single command:
docker system prune
To completely remove all containers, images, networks and volumes the below commands can be used. This may result in data loss so do not do this blindly.
First make sure no containers are running:
docker stop $(docker ps -a -q)
Purge the containers/images/networks:
docker system prune -a -f
Finally purge the volumes:
docker volume prune -f