Last active
          October 20, 2015 08:22 
        
      - 
      
- 
        Save dave-tucker/aac59f2098cb8fc118e6 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| set -e | |
| # Set Up Environment | |
| if [ -z $AWS_ACCESS_KEY_ID]; then | |
| echo "Please supply your AWS_ACCESS_KEY_ID" | |
| exit 1 | |
| fi | |
| if [ -z $AWS_SECRET_ACCESS_KEY]; then | |
| echo "Please supply your AWS_ACCESS_KEY_ID" | |
| exit 1 | |
| fi | |
| group_name="docker-networking" | |
| my_ip="$(wget -q -O- http://icanhazip.com)" | |
| # Get the AMI for your region from this list: https://wiki.debian.org/Cloud/AmazonEC2Image/Jessie | |
| # Paravirtual only - HVM AMI's and Docker Machine don't seem to be working well together | |
| export AWS_AMI="ami-971a65e0" | |
| export AWS_DEFAULT_REGION="eu-west-1" | |
| export AWS_VPC_ID="vpc-69c9a10c" | |
| export AWS_INSTANCE_TYPE="t1.micro" | |
| export AWS_SSH_USER="admin" | |
| # Set up Security Group in AWS | |
| aws ec2 create-security-group --group-name ${group_name} --description "A Security Group for Docker Networking" | |
| ## Permit SSH, required for Docker Machine | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 22 --cidr ${my_ip}/32 | |
| ## Permit Secure Docker Communications | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 2376 --cidr ${my_ip}/32 | |
| ## Permit Serf ports for Docker Discovery | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 7946 --cidr 0.0.0.0/0 | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 7946 --cidr 0.0.0.0/0 | |
| ## Permit Consul HTTP API | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 8500 --cidr 0.0.0.0/0 | |
| ## Permit VXLAN (for the "overlay" driver) | |
| aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 4789 --cidr 0.0.0.0/0 | |
| # Docker Machine Setup | |
| docker-machine create \ | |
| -d amazonec2 \ | |
| --amazonec2-security-group ${group_name} \ | |
| consul | |
| docker $(docker-machine config consul) run -d \ | |
| -p "8500:8500" \ | |
| -h "consul" \ | |
| progrium/consul -server -bootstrap | |
| docker-machine create \ | |
| -d amazonec2 \ | |
| --amazonec2-security-group ${group_name} \ | |
| --engine-install-url=https://test.docker.com | |
| --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" \ | |
| demo0 | |
| docker-machine create \ | |
| -d amazonec2 \ | |
| --amazonec2-security-group ${group_name} \ | |
| --engine-install-url=https://test.docker.com | |
| --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" \ | |
| demo1 | |
| # Workaround for https://github.com/docker/docker/issues/17047 | |
| docker-machine ssh demo0 'sudo sh -c "set -ex; systemctl stop docker || true; sed -i '\''/^ExecStart/ s/$/ --cluster-advertise='$(docker-machine ip demo0)':0'\'' /etc/systemd/system/docker.service; systemctl daemon-reload; systemctl start docker"' | |
| docker-machine ssh demo1 'sudo sh -c "set -ex; systemctl stop docker || true; sed -i '\''/^ExecStart/ s/$/ --cluster-advertise='$(docker-machine ip demo1)':0'\'' /etc/systemd/system/docker.service; systemctl daemon-reload; systemctl start docker"' | |
| docker network $(docker-machine config demo0) network create -d overlay my-net | |
| # run containers... remember to use `docker-machine config demoX` to run on the right host | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment