Skip to content

Instantly share code, notes, and snippets.

@linnv
Created May 14, 2016 15:23
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 linnv/b7565bb1bc85cd3474c37010377abb95 to your computer and use it in GitHub Desktop.
Save linnv/b7565bb1bc85cd3474c37010377abb95 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
cids=`docker ps -a | awk 'FNR>1 {print $1}'`
function stop() {
for v in $cids
do
echo "stop "$v
docker stop $v
done
check_code
echo "stop all containers "$cids
}
function start() {
for v in $cids
do
echo "starting "$v
docker start $v
done
check_code
echo "start all containers done "$cids
}
function unpause() {
for v in $cids
do
echo "unpausing "$v
docker unpause $v
done
check_code
echo "unpause all containers done "$cids
}
function pause() {
for v in $cids
do
echo "pausing "$v
docker pause $v
done
check_code
echo "pause all containers done "$cids
}
function remove() {
for v in $cids
do
echo "removing "$v
docker rm $v
done
check_code
echo "remove all containers done "$cids
}
function check_code() {
EXCODE=$?
if [ "$EXCODE" != "0" ]; then
echo "error occurs"
exit $EXCODE
fi
}
case $1 in
"0" )
start
;;
"1" )
stop
;;
"2" )
pause
;;
"3" )
unpause
;;
"4" )
remove
;;
* )
echo "usage: ./dockerctl.sh option
option:{
0: start all containers
1: stop all containers
2: pause all containers
3: unpause all containers
4: remove all containers
}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment