docker rmi $(docker images -a -q)
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)
Will remove all unused volume and images
docker image prune -a
docker volume prune
docker rm -vf $(docker ps -a -q --filter "status=exited")
docker rmi -f $(docker images -q -f "dangling=true")
docker volume rm -f $(docker volume ls -f "dangling=true")
docker volume prune -f
docker network prune -f
The sections below give a brief overview of identifying and removing objects, as well as links to the documentation for each command.
The docker ps command allows you to identify existing containers.
docker ps
docker ps -a
docker ps --all
docker ps -f "status=exited"
docker ps --filter "status=exited"
docker ps -q -f "status=exited"
docker ps --quiet --filter "status=exited"
Containers are removed using the docker rm command.
Remove an individual container by ID or name. Use "-v" or "--volumes" to remove associated volumes. Use "-f" or "--force" to remove running containers.
docker rm -vf b0479f9d1ea4
docker rm --volumes --force ol7_ords_con
docker rm -vf $(docker ps -a -q --filter "status=exited")
Images are displayed using the docker images command.
docker images
docker images -a
docker images --all
docker images -f "dangling=true"
docker images --filter "dangling=true"
docker images -q -f "dangling=true"
docker images --quiet --filter "dangling=true"
Images are removed using the docker rmi command.
docker rmi ffcd22192b23
docker rmi ol7_122:latest
docker rmi -f ffcd22192b23
docker rmi --force ol7_122:latest
docker rmi -f $(docker images -q -f "dangling=true")
Docker volumes are listed using the docker volume ls command.
docker volume ls
docker volume ls -f "dangling=true"
docker volume ls --filter "driver=local"
docker volume ls -q -f "driver=local"
docker volume ls --quiet --filter "driver=local"
Volumes are removed using the docker volume rm command.
docker volume rm test_vol
docker volume rm -f test_vol
docker volume rm --force test_vol
docker volume rm -f $(docker volume ls -f "dangling=true")
You can also use the docker volume prune command.
docker volume prune -f
Networks don't waste any disk space, but you might want to clean up unused networks anyway.
Networks are listed using the docker network ls command.
docker network ls
docker network ls -f "driver=bridge"
docker network ls --filter "driver=bridge"
docker network ls -q -f "driver=bridge"
docker network ls --quiet --filter "driver=bridge"
Networks are removed using the docker network rm command.
docker network rm my_network2
docker network rm 6466079abd47
Alternatively, you can remove unused networks using the docker network prune command.
docker network prune
docker network prune -f
docker network prune --force