Skip to content

Instantly share code, notes, and snippets.

@shankie-codes
Created April 1, 2016 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankie-codes/ed638d9bf3b8f98533e8e6450bddf9b6 to your computer and use it in GitHub Desktop.
Save shankie-codes/ed638d9bf3b8f98533e8e6450bddf9b6 to your computer and use it in GitHub Desktop.
create new docker machine with https-portal network
#!/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)"
# Rather than writing a separate docker-compose.yml, we do it here using the -f flag to use an input from stdin
echo '
# docker-compose.yml for my_wordpress site
https-portal:
image: steveltn/https-portal
restart: always
ports:
- 80:80
- 443:443
links:
- wordpress
environment:
- "DOMAINS='"$HOSTNAME"' -> http://wordpress"
- "PRODUCTION=true"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
wordpress:
image: wordpress
restart: always
links:
- db:mysql
volumes:
- /wordpress/uploads:/var/www/html/wp-content/uploads
- /wordpress/plugins:/var/www/html/wp-content/plugins
- /wordpress/themes:/var/www/html/wp-content/themes
db:
image: mariadb
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: kjhkjhafdqi
volumes:
- /db:/var/lib/mysql
' | docker-compose -p wp-ssl -f - up -d
# 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