docker delete everything code example

Example 1: remove all images docker

docker rmi $(docker images -a -q)

Example 2: docker remove all containers

docker rm $(docker ps -a -q)

Example 3: remove docker volume

docker-compose down
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)
docker-compose up -d

Example 4: docker delete all images

docker system prune

Example 5: delete all containers created x hours ago

# Delete all stopped containers
docker container prune

Example 6: docker delete container and image

# remove containers created between now upto 4hrs back
docker container prune --filter "until=4h"

# remove images created between now upto 4hrs back
docker image prune --filter "until=4h"