Skip to content

Instantly share code, notes, and snippets.

@mario21ic
Last active April 19, 2016 10:11
Show Gist options
  • Save mario21ic/963875a200cb7f87d1ac to your computer and use it in GitHub Desktop.
Save mario21ic/963875a200cb7f87d1ac to your computer and use it in GitHub Desktop.
docker_deploy.sh simple script to run an App PHP on Apache and MySQL
#!/bin/bash
IMG_PHP="tutum/apache-php:latest"
IMG_DB="mysql:latest"
CONT_DB="mysql_container"
CONT_PHP="php_container"
PASS_DB="clavedatabase"
DIR_SRC=$PWD"/src"
DB_DIR=$PWD"/data"
DB_NAME="database_name"
if [ -z $1 ]; then
ACTION="start"
else
ACTION=$1
fi
echo "Checking if containers "$CONT_DB" exists "
if [ ! -z $(docker ps -q -a -f name=$CONT_DB) ]
then
echo $ACTION"ing container "$CONT_DB
docker $ACTION $CONT_DB
else
echo "Running container "$CONT_DB
docker run -d -v $DB_DIR:/var/lib/mysql/$DB_NAME -p 3306:3306 --name=$CONT_DB -e MYSQL_ROOT_PASSWORD=$PASS_DB $IMG_DB
fi
echo "Checking if containers "$CONT_PHP" exists "
if [ ! -z $(docker ps -q -a -f name=$CONT_PHP) ]
then
echo $ACTION"ing container "$CONT_PHP
docker $ACTINO $CONT_PHP
else
echo "Running container "$CONT_PHP
docker run --name $CONT_PHP --link $CONT_DB:mysql -d -p 80:80 -v $DIR_SRC:/var/www \
-v $PWD/access.log:/var/log/apache2/access.log \
-v $PWD/error.log:/var/log/apache2/error.log $IMG_PHP
fi
echo "Cleaning logs"
echo "" > access.log
echo "" > error.log
echo "Logging..."
tail -f ./error.log
@mario21ic
Copy link
Author

docker_deploy.sh simple script to run an App PHP on Apache and MySQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment