See also https://github.com/docker/docker/pull/26108 New Data Management commands
Super duper awesome, such a welcome addition to Docker.
docker system prune
or
docker image prune
should do the trick next version!
If someone uses earlier version
docker rmi $(docker images -q -f "dangling=true")
Thanks. Very helpful!
Cleaning up after Docker right now is as easy as issuing
docker system prune
This works starting with version 1.25, you can read more here.
Previously, or if you prefer to have a bit more control, you could use the following:
$ docker rm -v $(docker ps -aq -f 'status=exited')
$ docker rmi $(docker images -aq -f 'dangling=true')
# ATTENTION: this will also remove volumes of docker-compose if the containers are barely stopped
$ docker volume rm $(docker volume ls -q -f 'dangling=true')
If you want more details about cleaning up after Docker, check out this article.
I used these to clean images
sudo docker rmi -f $(sudo docker images | grep “” | awk “{print $3}”)
I think this is similar
docker images -f "dangling=true" --format "{{.ID}}" | xargs docker rmi -
I use the following command to clean up local images. I prefer removing everything and treating the images as more ephemeral. If I need again, I build it again. Warning - this will force any running to exit non-gracefully, and will now remove / delete all images for example.
docker images -q | xargs docker rmi -f