Skip to content

Instantly share code, notes, and snippets.

@remoteur
Last active August 29, 2015 14:18
Show Gist options
  • Save remoteur/6b12ce450d0005acc287 to your computer and use it in GitHub Desktop.
Save remoteur/6b12ce450d0005acc287 to your computer and use it in GitHub Desktop.
Docker create wordpress instance
#!/bin/bash
WEBNODE_ROOT='/srv/webnode'
DB_ADDRESS=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' db-server)
DB_ROOT_PASSWD=$(docker inspect --format '{{ .Config.Env }}' db-server | awk {'print $1'} | awk -F '=' {'print $2'})
echo "Enter wordress domain: "
read WP_DOMAIN
WP_DOMAIN_PASSWD=$(openssl rand -hex 10)
WP_DOMAIN_NAME=$(echo $WP_DOMAIN | awk -F '.' {'print $1'})
echo "Creating container web root in $WEBNODE_ROOT/webnode-$WP_DOMAIN/www"
mkdir -p $WEBNODE_ROOT/webnode-$WP_DOMAIN/www
echo "Downloading Wordpress to webnode-$WP_DOMAIN"
curl -s https://wordpress.org/latest.tar.gz | tar -zx -C /tmp/
mv /tmp/wordpress/* $WEBNODE_ROOT/webnode-$WP_DOMAIN/www
rmdir /tmp/wordpress
echo "Creating Wordpress database"
docker exec db-server mysql -uroot -p$DB_ROOT_PASSWD -e "CREATE DATABASE $WP_DOMAIN_NAME; GRANT ALL PRIVILEGES ON $WP_DOMAIN_NAME.* TO '$WP_DOMAIN_NAME'@'%' IDENTIFIED BY '$WP_DOMAIN_PASSWD'; FLUSH PRIVILEGES;"
echo "Adjusting wp-config.php"
sed -e "s/database_name_here/$WP_DOMAIN_NAME/
s/username_here/$WP_DOMAIN_NAME/
s/password_here/$WP_DOMAIN_PASSWD/
s/localhost/mysql/
/'AUTH_KEY'/s/put your unique phrase here/`openssl rand -hex 10`/
/'SECURE_AUTH_KEY'/s/put your unique phrase here/`openssl rand -hex 10`/
/'LOGGED_IN_KEY'/s/put your unique phrase here/`openssl rand -hex 10`/
/'NONCE_KEY'/s/put your unique phrase here/`openssl rand -hex 10`/
/'AUTH_SALT'/s/put your unique phrase here/`openssl rand -hex 10`/
/'SECURE_AUTH_SALT'/s/put your unique phrase here/`openssl rand -hex 10`/
/'LOGGED_IN_SALT'/s/put your unique phrase here/`openssl rand -hex 10`/
/'NONCE_SALT'/s/put your unique phrase here/`openssl rand -hex 10`/" $WEBNODE_ROOT/webnode-$WP_DOMAIN/www/wp-config-sample.php > $WEBNODE_ROOT/webnode-$WP_DOMAIN/www/wp-config.php
rm $WEBNODE_ROOT/webnode-$WP_DOMAIN/www//wp-config-sample.php
echo "Adjusting permissions for www-data"
chown -R 33:33 $WEBNODE_ROOT/webnode-$WP_DOMAIN/www
docker run --name webnode-$WP_DOMAIN -e VIRTUAL_HOST=$WP_DOMAIN -v $WEBNODE_ROOT/webnode-$WP_DOMAIN/www:/var/www/ --link db-server:mysql -d webnode:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment