Skip to content

Instantly share code, notes, and snippets.

@pk
Created January 10, 2019 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pk/c7150ea67fc687fed5451334e3b52790 to your computer and use it in GitHub Desktop.
Save pk/c7150ea67fc687fed5451334e3b52790 to your computer and use it in GitHub Desktop.
Sleep script to stop all Docker containers
#!/bin/bash
exec &> ~/.sleep.log
# Author: pavel@fry-it.com
# 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