Skip to content

Instantly share code, notes, and snippets.

@JeffBelback
Last active May 25, 2024 20:19
Show Gist options
  • Save JeffBelback/5687bb02f3618965ca8f to your computer and use it in GitHub Desktop.
Save JeffBelback/5687bb02f3618965ca8f to your computer and use it in GitHub Desktop.
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
containers=`docker ps -a -q`
if [ -n "$containers" ] ; then
docker stop $containers
fi
# Delete all containers
containers=`docker ps -a -q`
if [ -n "$containers" ]; then
docker rm -f -v $containers
fi
# Delete all images
images=`docker images -q -a`
if [ -n "$images" ]; then
docker rmi -f $images
fi
@tudorpavel
Copy link

tudorpavel commented Feb 13, 2018

Not sure if it's a good idea or not, but you can also remove volumes:

docker volume rm $(docker volume ls -q)

Oh and by the way, there is also docker system prune.

@sysrqbr
Copy link

sysrqbr commented Feb 16, 2018

thks!

@mauroherlein
Copy link

thanks!

@Marvinified
Copy link

Thanks man

@knyga
Copy link

knyga commented Mar 23, 2019

Useful

@JeffBelback
Copy link
Author

Updated with implementation from @aaryno. Good stuff.

@hack3r-0m
Copy link

please add remove all volumes too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment