When running Docker for a long time, there are a lot of images in system. How can I remove all unused Docker images at once safety to free up the storage?
In addition, I also want to remove images pulled months ago, which have the correct TAG
.
So, I'm not asking for removing untagged images only. I'm searching for a way to remove general unused images, which includes both untagged and other images such as pulled months ago with correct TAG
.
Update the second (2017-07-08):
Refer (again) to VonC, using the even more recent
system prune
. The impatient can skip the prompt with the-f, --force
option:The impatient and reckless can additionally remove "unused images not just the dangling ones" with the
-a, --all
option:https://docs.docker.com/engine/reference/commandline/system_prune/
Update:
Refer to VonC's answer which uses the recently added
prune
commands. Here is the corresponding shell alias convenience:Old answer:
Delete stopped (exited) containers:
Delete unused (dangling) images:
If you have exercised extreme caution with regard to irrevocable data loss, then you can delete unused (dangling) volumes (v1.9 and up):
Here they are in a convenient shell alias:
References:
docker ps -f
docker rm
docker images -f
docker rmi
docker volume ls
docker volume rm
How to remove a tagged image
docker rmi the tag first
docker rmi the image.
# that can be done in one docker rmi call e.g.: # docker rmi <repo:tag> <imageid>
(this works Nov 2016, Docker version 1.12.2)
e.g.
e.g. Scripted remove anything older than 2 weeks.