Skip to content

Instantly share code, notes, and snippets.

@thestonefox
Created February 21, 2014 14:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thestonefox/9135499 to your computer and use it in GitHub Desktop.
Save thestonefox/9135499 to your computer and use it in GitHub Desktop.
Docker container management script to start, stop and restart containers from source
#!/bin/bash
function start() {
docker build -rm -t myapp_image .
docker run -d -name myapp_container myapp_image
}
function stop() {
docker stop myapp_container && docker rm myapp_container
}
function restart() {
stop
start
}
function_exists() {
declare -f -F $1 > /dev/null
return $?
}
if [ "$UID" -ne 0 ]
then echo "Please run as root"
exit
fi
if [ $# -lt 1 ]
then
echo "Usage : $0 start|stop|restart "
exit
fi
case "$1" in
start) function_exists start && start
;;
stop) function_exists stop && stop
;;
restart) function_exists restart && restart
;;
*) echo "Invalid command - Valid->start|stop|restart"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment