Docker examples: Cleaning up unused Resources

Last updated:
Table of Contents

Delete all Images

$ docker rmi -f $(docker images --quiet)

Or, alternatively, using sudo:

$ sudo docker rmi -f $(sudo docker images --quiet)

Delete Dangling (unused) Images

$ docker rmi $(docker images --quiet --filter "dangling=true")

Delete all Containers

$ docker rm $(docker ps --all --quiet)

Delete all Stopped containers

$ docker rm $(docker ps --quiet --filter status=exited)

Delete old volumes

$ docker volume rm $(docker volume ls --quiet --filter dangling=true)
$ docker volume ls --quiet --filter dangling=true | xargs -r docker volume rm

Troubleshooting: Cannot connect to the Docker daemon. Is the docker daemon running on this host?

You may need to add sudo to commands you run.

See also

Dialogue & Discussion