Created
January 10, 2019 14:37
-
-
Save pk/c7150ea67fc687fed5451334e3b52790 to your computer and use it in GitHub Desktop.
Sleep script to stop all Docker containers
This file contains hidden or 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 | |
exec &> ~/.sleep.log | |
# Author: [email protected] | |
# Version: 0.0.1 | |
echo ".sleep triggered at $(date)" | |
# This have to be here otherwise launchctl won't find Docker commands | |
DOCKER=/usr/local/bin/docker | |
if [ ! -x "$(command -v $DOCKER)" ] | |
then | |
echo "Docker not installed!" | |
exit 1 | |
fi | |
CONTAINERS=( $($DOCKER ps -q) ) | |
if [ "${#CONTAINERS[@]}" -gt 0 ] | |
then | |
echo "Will attempt to stop all Docker containers..." | |
$DOCKER stop "${CONTAINERS[@]}" | |
else | |
echo "No running containers!" | |
fi | |
echo ".sleep done at $(date)" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment