Skip to content

Instantly share code, notes, and snippets.

@shankie-codes
Last active April 1, 2016 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankie-codes/f1a9ec79ea35a4983edc7a1d9326d6f9 to your computer and use it in GitHub Desktop.
Save shankie-codes/f1a9ec79ea35a4983edc7a1d9326d6f9 to your computer and use it in GitHub Desktop.
Create WordPress nginx droplet on digital ocean using Docker
#!/bin/bash
echo "Enter the hostname that you'd like to create:"
read HOSTNAME
# Can be defined as an environment variable
if [ -z "$DO_TOKEN" ]; then
echo "Enter your Digital Ocean access token:"
read DO_TOKEN
fi
# Can be defined as an environment variable
if [ -z "$PUBLIC_KEYS" ]; then
echo "Enter your public keys followed by Ctrl-D:"
PUBLIC_KEYS=$(cat)
fi
docker-machine create \
--driver digitalocean \
--digitalocean-backups=true \
--digitalocean-region=lon1 \
--digitalocean-access-token=$DO_TOKEN \
$HOSTNAME
# Set the context for docker-machine
eval "$(docker-machine env $HOSTNAME)"
docker run -p 80:80 -p 3306:3306 --restart=always --name docker-wordpress-nginx -d -v /wordpress/uploads:/usr/share/nginx/www/wp-content/uploads -v /wordpress/plugins:/usr/share/nginx/www/wp-content/plugins -v /wordpress/themes:/usr/share/nginx/www/wp-content/themes eugeneware/docker-wordpress-nginx
# Give the machine some swap
docker-machine ssh $HOSTNAME \
"
fallocate -l 2G /swapfile && \
chmod 600 /swapfile && \
mkswap /swapfile && \
swapon /swapfile && \
swapon -s \
sudo bash -c 'echo \"/swapfile none swap sw 0 0\" >> /etc/fstab' && \
sysctl vm.swappiness=10 && \
sudo bash -c 'echo \"vm.swappiness=10\" >> /etc/sysctl.conf' && \
sysctl vm.vfs_cache_pressure=50 && \
sudo bash -c 'echo \"vm.vfs_cache_pressure = 50\" >> /etc/sysctl.conf' \
"
echo $PUBLIC_KEYS | docker-machine ssh $HOSTNAME sudo bash -c 'cat >> /root/.ssh/authorized_keys'
# Print the IP for the user
docker-machine ip $HOSTNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment