Skip to content

Instantly share code, notes, and snippets.

@mgor mgor/dev-env.sh
Last active Jan 9, 2016

Embed
What would you like to do?
#!/usr/bin/env bash
DATABASE_CONTAINER="dev-db"
WEBSERVER_CONTAINER="dev-web"
MYSQL_ROOT_PASSWORD="my-secret"
MYSQL_USER="dev"
MYSQL_PASSWORD="dev"
MYSQL_DATABASE="wordpress"
docker pull wordpress:latest
docker pull mysql:${MYSQL_VERSION}
docker inspect d${DATABASE_CONTAINER} &> /dev/null || docker create \
-v /var/lib/mysql \
--name d${DATABASE_CONTAINER} \
mysql:${MYSQL_VERSION} \
/bin/true
docker inspect ${DATABASE_CONTAINER} &> /dev/null && docker start ${DATABASE_CONTAINER}
docker inspect ${DATABASE_CONTAINER} &> /dev/null || docker run --name ${DATABASE_CONTAINER} \
-e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} \
-e MYSQL_USER=${MYSQL_USER} \
-e MYSQL_PASSWORD=${MYSQL_PASSWORD} \
-e MYSQL_DATABASE=${MYSQL_DATABASE} \
--volumes-from d${DATABASE_CONTAINER} \
-v $(pwd)/config/:/docker-entrypoint-initdb.d/ \
-d mysql:${MYSQL_VERSION}
test $? -ne 0 && { echo "Failed to start database container."; exit 1; }
docker inspect ${WEBSERVER_CONTAINER} &> /dev/null && docker start ${WEBSERVER_CONTAINER}
docker inspect ${WEBSERVER_CONTAINER} &> /dev/null || docker run --name ${WEBSERVER_CONTAINER} \
--link ${DATABASE_CONTAINER}:mysql \
-v $(pwd)/config/php.ini-development:/usr/local/etc/php/php.ini \
-v $(realpath $(pwd)/../src)/wp-content/uploads:/var/www/html/wp-content/uploads \
-v $(realpath $(pwd)/../src)/wp-content/themes/my-custom-theme/:/var/www/html/wp-content/themes/my-custom-theme/ \
-v $(realpath $(pwd)/../src)/wp-content/plugins/:/var/www/html/wp-content/plugins/ \
-e WORDPRESS_DB_USER=${MYSQL_USER} \
-e WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD} \
-e WORDPRESS_DB_NAME=${MYSQL_DATABASE} \
-e WORDPRESS_TABLE_PREFIX="wp_" \
-p 80:80 -d wordpress:4
test $? -ne 0 && { echo "Failed to start webserver container."; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.