Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created June 29, 2019 04:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/5ea97bb10eddd311e57b1a5a0c0f9432 to your computer and use it in GitHub Desktop.
Save timjonesdev/5ea97bb10eddd311e57b1a5a0c0f9432 to your computer and use it in GitHub Desktop.
A cleanup script for docker resources, if you don't have `docker system prune` available. WARNING: This will delete all containers, images, and volumes.
#!/usr/bin/env bash
echo "Running docker cleanup script"
echo "Stopping all containers"
docker stop $(docker ps -a -q) # Stop all containers
echo "Removing stopped containers"
docker rm $(docker ps -a -q) # Remove all stopped containers
echo "Removing all images"
docker rmi $(docker images -a -q) # Remove all images
echo "Removing all volumes"
docker volume rm $(docker volume ls -qf dangling=true) # Remove all volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment