Created
February 21, 2014 14:46
-
-
Save thestonefox/9135499 to your computer and use it in GitHub Desktop.
Docker container management script to start, stop and restart containers from source
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 | |
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