Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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