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 |
This comment has been minimized.
This comment has been minimized.
Thank you. |
This comment has been minimized.
This comment has been minimized.
Great stuff |
This comment has been minimized.
This comment has been minimized.
Too clean. ty |
This comment has been minimized.
This comment has been minimized.
thanks |
This comment has been minimized.
This comment has been minimized.
I had issues with empty values and
|
This comment has been minimized.
This comment has been minimized.
Delete all the images,
as
|
This comment has been minimized.
This comment has been minimized.
As you need root to run docker you should rune these commands as:
|
This comment has been minimized.
This comment has been minimized.
@DonatasD you don't need root to run docker. |
This comment has been minimized.
This comment has been minimized.
I had to add |
This comment has been minimized.
This comment has been minimized.
Great script! Thanks! |
This comment has been minimized.
This comment has been minimized.
you da best |
This comment has been minimized.
This comment has been minimized.
Not sure if it's a good idea or not, but you can also remove volumes:
Oh and by the way, there is also docker system prune. |
This comment has been minimized.
This comment has been minimized.
thks! |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks man |
This comment has been minimized.
This comment has been minimized.
Useful |
This comment has been minimized.
This comment has been minimized.
Updated with implementation from @aaryno. Good stuff. |
This comment has been minimized.
This comment has been minimized.
please add remove all volumes too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Every of these should be included as a native command in docker. Great!