Skip to content

Instantly share code, notes, and snippets.

@muriloloffi
Last active January 4, 2023 19:30
Show Gist options
  • Save muriloloffi/cbd5310a558aed490ec59e417ca5b76d to your computer and use it in GitHub Desktop.
Save muriloloffi/cbd5310a558aed490ec59e417ca5b76d to your computer and use it in GitHub Desktop.
Shortcut script to turn off every docker container and network.
#!/bin/bash
#For ease of use, you can set an Alias to this script in your shell session "rc" file.
#i.e. alias sdc="/home/$USER/turn-docker-containers-off.sh"
containers=$(docker ps -qa)
if [[ $? != 0 ]]; then
echo "Command failed."
exit 127
elif [[ $containers ]]; then
docker stop $(docker ps -qa) && docker rm $(docker ps -qa)
else
echo "No containers found."
fi
docker network prune -f
exit 0
# This script is licensed under CC0 1.0. Therefore, it should be treated as public domain.
# Full license disclosure at: https://creativecommons.org/publicdomain/zero/1.0/legalcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment