Last active
January 4, 2023 19:30
-
-
Save muriloloffi/cbd5310a558aed490ec59e417ca5b76d to your computer and use it in GitHub Desktop.
Shortcut script to turn off every docker container and network.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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