Docker - free up space
WARNING: commands below delete stopped containers and remove all their data. Make sure you don’t have any containers or valuable data that you need to backup.
Remove exited containers
When a docker container exits, it leaves the stopped container on the system. Below command will remove that stopped container.
docker rm -v $(docker ps -a -q -f status=exited)
Remove dangling images
Docker keeps all of the images that you have used in the disk (local cache), even if those are not actively running. Below command will remove all those unwanted images.
docker rmi $(docker images -f "dangling=true" -q)
All-in-one command
Execute below command if you want to delete and remove any stopped containers and unused images.
docker system prune -a