Skip to content

Instantly share code, notes, and snippets.

@rgdevment
Last active July 1, 2020 16:06
Show Gist options
  • Save rgdevment/e5e9a652e3b732cdc51de1bd77198884 to your computer and use it in GitHub Desktop.
Save rgdevment/e5e9a652e3b732cdc51de1bd77198884 to your computer and use it in GitHub Desktop.
[Clear Docker] destroy and prune container, images, volumes and networks in docker #docker
#!/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
# Clear docker system
docker system prune --volumes --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment