How to remove all local Docker Docker images
I recently started using Docker and never really figured out what instead ctrl-c
or docker-compose stop
should I use docker-compose down
to get rid of my experiments. Now I have a large number of unneeded docker images.
Is there a flag I can run to remove all local images and docker containers?
Something like the docker rmi --all --force
-all flag doesn't exist, but I'm looking for something with a similar idea.
source to share
Use this to remove everything :
docker system prune -a --volumes
Remove all unused containers, volumes, networks and images
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
https://docs.docker.com/engine/reference/commandline/system_prune/#extended-description
source to share
docker image prune -a
Delete all unused images, not just dangling ones. Add a parameter
-f
to strength.
Local docker version: 17.09.0-ce, Git commit: afdb6d4, OS / Arch: darwin / amd64
$ docker image prune -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker image prune [OPTIONS]
Remove unused images
Options:
-a, --all Remove all unused images, not just dangling ones
--filter filter Provide filter values (e.g. 'until=<timestamp>')
-f, --force Do not prompt for confirmation
--help Print usage
source to share
Simple and convenient commands
Delete all images
docker rmi $(docker images -a)
Remove containers that are in exit state
docker rm $(docker ps -a -f status=exited -q)
Remove containers that are in the created state
docker rm $(docker ps -a -f status=created -q)
NOTE: remove all containers then remove images
source to share
To remove all images:
docker rmi $(docker images -a -q)
where -a is everything and -q only returns image IDs
To remove unused images and containers:
docker system prune
be careful, as if you are using Docker Swarm and your local machine is joining the remote Swarm (as administrator / worker) your local machine will be a deployed repo. doing this thus removes the deployed images.
source to share