Question:
I recently started using Docker and never realized that I should use
docker-compose down
instead ofctrl-c
ordocker-compose stop
to get rid of my experiments. I now have a large number of unneeded docker images locally.Is there a flag I can run to delete all the local docker images & containers?
Something like
docker rmi --all --force
–all flag does not exist but I am looking for something with similar idea.
Answers:
Unix
To delete all containers including its volumes use,
docker rm -vf $(docker ps -aq)
To delete all the images,
docker rmi -f $(docker images -aq)
Remember, you should remove all the containers before removing all the images from which those containers were created.
Windows – Powershell
docker images -a -q | % { docker image rm $_ -f }
Windows – cmd.exe
for /F %i in ('docker images -a -q') do docker rmi -f %i
Use this to delete everything:
docker system prune -a --volumes
WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all volumes not used by at least one container - all images without at least one container associated to them - all build cache
That’s all. Tnx for attention 🙂
Similar Posts:
- How to install docker on debian 10 /11 ( buster / bullseye )
- Docker: Launching a Container from an Image
- how to install docker-compose package
- how to Install Docker CE and Docker Compose on Debian 10 / 11
- Disable docker container autostart
125