How can I delete all local Docker images?
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 Question
00:38 Accepted answer (Score 1745)
01:18 Answer 2 (Score 466)
01:48 Answer 3 (Score 56)
02:27 Answer 4 (Score 49)
03:07 Thank you
--
Full question
https://stackoverflow.com/questions/4478...
Answer 1 links:
https://docs.docker.com/engine/reference...
Answer 2 links:
[link]: https://www.digitalocean.com/community/t...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #docker #dockercompose
#avk47
ACCEPTED ANSWER
Score 2242
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
ANSWER 2
Score 679
Use this to delete 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
ANSWER 3
Score 58
docker image prune -a
Remove all unused images, not just dangling ones. Add
-foption to force.
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
ANSWER 4
Score 21
Easy and handy commands
To delete all images
docker rmi $(docker images -a)
To delete containers which are in exited state
docker rm $(docker ps -a -f status=exited -q)
To delete containers which are in created state
docker rm $(docker ps -a -f status=created -q)
NOTE: Remove all the containers then remove the images