├── counter └── docker-compose.yml ├── multihost-local.sh ├── swarm-local.sh ├── README.md ├── applescript ├── swarm-compose.scpt ├── swarm-script.scpt └── docker-mh-net.scpt ├── multihost-aws.sh └── swarm-aws.sh /counter/docker-compose.yml: -------------------------------------------------------------------------------- 1 | web: 2 | image: bfirsh/compose-mongodb-demo 3 | environment: 4 | - "MONGO_HOST=counter_mongo_1" 5 | - "constraint:node==swl-demo0" 6 | ports: 7 | - "80:5000" 8 | 9 | mongo: 10 | image: mongo 11 | -------------------------------------------------------------------------------- /multihost-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Docker Machine Setup 6 | docker-machine create \ 7 | -d virtualbox \ 8 | mhl-consul 9 | 10 | docker $(docker-machine config mhl-consul) run -d \ 11 | -p "8500:8500" \ 12 | -h "consul" \ 13 | progrium/consul -server -bootstrap 14 | 15 | docker-machine create \ 16 | -d virtualbox \ 17 | --engine-opt="cluster-store=consul://$(docker-machine ip mhl-consul):8500" \ 18 | --engine-opt="cluster-advertise=eth1:0" \ 19 | mhl-demo0 20 | 21 | docker-machine create \ 22 | -d virtualbox \ 23 | --engine-opt="cluster-store=consul://$(docker-machine ip mhl-consul):8500" \ 24 | --engine-opt="cluster-advertise=eth1:0" \ 25 | mhl-demo1 26 | -------------------------------------------------------------------------------- /swarm-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Docker Machine Setup 6 | docker-machine create \ 7 | -d virtualbox \ 8 | swl-consul 9 | 10 | docker $(docker-machine config swl-consul) run -d \ 11 | -p "8500:8500" \ 12 | -h "consul" \ 13 | progrium/consul -server -bootstrap 14 | 15 | docker-machine create \ 16 | -d virtualbox \ 17 | --virtualbox-disk-size 50000 \ 18 | --swarm \ 19 | --swarm-master \ 20 | --swarm-discovery="consul://$(docker-machine ip swl-consul):8500" \ 21 | --engine-opt="cluster-store=consul://$(docker-machine ip swl-consul):8500" \ 22 | --engine-opt="cluster-advertise=eth1:0" \ 23 | swl-demo0 24 | 25 | docker-machine create \ 26 | -d virtualbox \ 27 | --virtualbox-disk-size 50000 \ 28 | --swarm \ 29 | --swarm-discovery="consul://$(docker-machine ip swl-consul):8500" \ 30 | --engine-opt="cluster-store=consul://$(docker-machine ip swl-consul):8500" \ 31 | --engine-opt="cluster-advertise=eth1:0" \ 32 | swl-demo1 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-network-demos 2 | Demos of Docker's New Networking 3 | 4 | This repo contains a bunch of scripts for you to get started with Docker's new networking features 5 | 6 | ## Pre-Requsites 7 | 8 | These scripts assume the following 9 | 10 | 1) You have Docker Machine installed 11 | 2) You are using Docker 1.9 or later 12 | 13 | Both of these components can be installed using the [Docker Toolbox](https://www.docker.com/docker-toolbox) 14 | 15 | ## What's what? 16 | 17 | | Environment | Script Name | 18 | |----------------------------------------|----------------------| 19 | | Multi-host Networking using Virtualbox | `multihost-local.sh` | 20 | | Multi-host Networking using Amazon EC2 | `multihost-aws.sh` | 21 | | Swarm w/ Networking on Virtualbox | `swarm-local.sh` | 22 | | Swarm w/ Networking on Amazon EC2 | `swarm-aws.sh` | 23 | 24 | ## Adapting to your environment 25 | 26 | So you want to use a different Docker Machine driver! Cool. 27 | Here are some things you might want to know 28 | 29 | - You can "borrow" the security group configuration from the AWS scripts 30 | - You *MUST* check the interface name used for `cluster-advertise`. Pick the wrong name and your daemon won't start 31 | 32 | ## What to do next 33 | 34 | Check out the [docs](http://docs.docker.com/engine/userguide/networking/dockernetworks/) 35 | Have fun! 36 | 37 | ## Contributing? 38 | 39 | Made changes? Want to contribute a new script for another cloud provider... or even for networking across clouds? 40 | Raise a PR! 41 | 42 | ## License 43 | 44 | Apache 2.0 45 | https://www.apache.org/licenses/LICENSE-2.0.txt 46 | -------------------------------------------------------------------------------- /applescript/swarm-compose.scpt: -------------------------------------------------------------------------------- 1 | tell application "iTerm" 2 | activate 3 | tell current session of current terminal 4 | write text "echo \"First, set up your environment\" | figlet | lolcat" 5 | delay 5 6 | write text "echo \"The instructions are in the blog post\" | figlet | lolcat" 7 | delay 5 8 | write text "echo \"Here's mine...\" | figlet | lolcat" 9 | delay 5 10 | write text "docker-machine ls" 11 | delay 5 12 | write text "echo \"Now, let's talk to swarm\" | figlet | lolcat" 13 | delay 5 14 | write text "eval $(docker-machine env --swarm swl-demo0)" 15 | delay 5 16 | write text "echo \"Here is our docker-compose.yml file\" | figlet | lolcat" 17 | delay 5 18 | write text "cat docker-compose.yml" 19 | delay 5 20 | write text "echo \"Let's deploy this to our Swarm\" | figlet | lolcat" 21 | delay 5 22 | write text "docker-compose --x-networking --x-network-driver overlay up -d" 23 | delay 5 24 | write text "echo \"OK! Compose created a network for us\" | figlet | lolcat" 25 | delay 5 26 | write text "docker network ls" 27 | delay 5 28 | write text "echo \"And Swarm spread our containers across our hosts\" | figlet | lolcat" 29 | delay 5 30 | write text "docker ps -a" 31 | delay 5 32 | write text "echo \"And our application is working...\" | figlet | lolcat" 33 | delay 5 34 | write text "wget -qO- http://`docker-machine ip swl-demo0`" 35 | delay 5 36 | write text "wget -qO- http://`docker-machine ip swl-demo0`" 37 | delay 5 38 | write text "wget -qO- http://`docker-machine ip swl-demo0`" 39 | delay 5 40 | write text "echo \"Simples!\" | figlet | lolcat" 41 | delay 5 42 | end tell 43 | end tell 44 | -------------------------------------------------------------------------------- /applescript/swarm-script.scpt: -------------------------------------------------------------------------------- 1 | tell application iTerm 2 | activate 3 | tell current session of current terminal 4 | write text "echo \"First, set up your environment\" | figlet | lolcat" 5 | delay 5 6 | write text "echo \"The instructions are in the blog post\" | figlet | lolcat" 7 | delay 5 8 | write text "echo \"Here's mine...\" | figlet | lolcat" 9 | delay 5 10 | write text "docker-machine ls" 11 | delay 5 12 | write text "echo \"Now, let's talk to swarm\" | figlet | lolcat" 13 | delay 5 14 | write text "eval $(docker-machine env --swarm swl-demo0)" 15 | delay 5 16 | write text "echo \"Swarm can show you all of your networks\" | figlet | lolcat" 17 | delay 5 18 | write text "docker network ls" 19 | delay 5 20 | write text "echo \"Let's create a new one\" | figlet | lolcat" 21 | delay 5 22 | write text "docker network create -d overlay myapp" 23 | delay 5 24 | write text "echo \"OK! Here it is in Swarm\" | figlet | lolcat" 25 | delay 5 26 | write text "docker network ls" 27 | delay 5 28 | write text "docker network inspect myapp" 29 | delay 5 30 | write text "echo \"Let's create two containers\" | figlet | lolcat" 31 | delay 5 32 | write text "echo \"Nginx on swl-demo0\" | figlet | lolcat" 33 | delay 5 34 | write text "echo \"And a client on swl-demo1\" | figlet | lolcat" 35 | delay 5 36 | write text "docker run -itd --name=web --net=myapp --env=\"constraint:node==swl-demo0\" nginx" 37 | delay 5 38 | write text "docker run -it --rm --net=myapp --env=\"constraint:node==swl-demo1\" busybox wget -O- http://web" 39 | delay 5 40 | write text "echo \"That's how easy it is for container to talk across hosts\" | figlet | lolcat 41 | delay 5 42 | end tell 43 | end tell 44 | -------------------------------------------------------------------------------- /applescript/docker-mh-net.scpt: -------------------------------------------------------------------------------- 1 | tell application "iTerm" 2 | activate 3 | tell current session of current terminal 4 | write text "echo \"First, set up your environment\" | figlet | lolcat" 5 | delay 5 6 | write text "echo \"The instructions are in the blog post\" | figlet | lolcat" 7 | delay 5 8 | write text "echo \"Here's mine...\" | figlet | lolcat" 9 | delay 5 10 | write text "docker-machine ls" 11 | delay 5 12 | write text "echo \"Now, let's take a look at the networks available on each host\" | figlet | lolcat" 13 | delay 5 14 | write text "docker $(docker-machine config mhl-demo0) network ls" 15 | delay 5 16 | write text "docker $(docker-machine config mhl-demo1) network ls" 17 | delay 5 18 | write text "echo \"Let's create a new one\" | figlet | lolcat" 19 | delay 5 20 | write text "docker $(docker-machine config mhl-demo0) network create -d overlay myapp" 21 | delay 5 22 | write text "echo \"OK! Here it is on mhl-demo0\" | figlet | lolcat" 23 | delay 5 24 | write text "docker $(docker-machine config mhl-demo0) network ls" 25 | delay 5 26 | write text "echo \"And it's also on mhl-demo1 too\" | figlet | lolcat" 27 | delay 5 28 | write text "docker $(docker-machine config mhl-demo1) network ls" 29 | delay 5 30 | write text "echo \"Let's create two containers\" | figlet | lolcat" 31 | delay 5 32 | write text "echo \"Nginx on mhl-demo0\" | figlet | lolcat" 33 | delay 5 34 | write text "echo \"And a client on mhl-demo1\" | figlet | lolcat" 35 | delay 5 36 | write text "docker $(docker-machine config mhl-demo0) run -itd --name=web --net=myapp nginx" 37 | delay 10 38 | write text "docker $(docker-machine config mhl-demo1) run -it --rm --net=myapp busybox wget -qO- http://web" 39 | delay 10 40 | write text "echo \"That's how easy it is for container to talk across hosts\" | figlet | lolcat" 41 | end tell 42 | end tell 43 | -------------------------------------------------------------------------------- /multihost-aws.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | #### Set Up Environment 6 | 7 | if [ -z $AWS_ACCESS_KEY_ID]; then 8 | echo "Please supply your AWS_ACCESS_KEY_ID" 9 | exit 1 10 | fi 11 | if [ -z $AWS_SECRET_ACCESS_KEY]; then 12 | echo "Please supply your AWS_ACCESS_KEY_ID" 13 | exit 1 14 | fi 15 | 16 | group_name="docker-networking" 17 | my_ip="$(wget -q -O- http://icanhazip.com)" 18 | # Get the AMI for your region from this list: https://wiki.debian.org/Cloud/AmazonEC2Image/Jessie 19 | # Paravirtual only - HVM AMI's and Docker Machine don't seem to be working well together 20 | export AWS_AMI="ami-971a65e0" 21 | export AWS_DEFAULT_REGION="eu-west-1" 22 | # This is my default VPC, yours will be different 23 | export AWS_VPC_ID="vpc-69c9a10c" 24 | export AWS_INSTANCE_TYPE="t1.micro" 25 | export AWS_SSH_USER="admin" 26 | 27 | 28 | #### Set up Security Group in AWS 29 | 30 | aws ec2 create-security-group --group-name ${group_name} --description "A Security Group for Docker Networking" 31 | # Permit SSH, required for Docker Machine 32 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 22 --cidr ${my_ip}/32 33 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 2376 --cidr ${my_ip}/32 34 | # Permit Serf ports for discovery 35 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 7946 --cidr 0.0.0.0/0 36 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 7946 --cidr 0.0.0.0/0 37 | # Permit Consul HTTP API 38 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 8500 --cidr 0.0.0.0/0 39 | # Permit VXLAN 40 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 4789 --cidr 0.0.0.0/0 41 | 42 | ##### Docker Machine Setup 43 | 44 | docker-machine create \ 45 | -d amazonec2 \ 46 | --amazonec2-security-group ${group_name} \ 47 | mha-consul 48 | 49 | docker $(docker-machine config mha-consul) run -d \ 50 | -p "8500:8500" \ 51 | -h "consul" \ 52 | progrium/consul -server -bootstrap 53 | 54 | docker-machine create \ 55 | -d amazonec2 \ 56 | --amazonec2-security-group ${group_name} \ 57 | --engine-opt="cluster-store=consul://$(docker-machine ip mha-consul):8500" \ 58 | --engine-opt="cluster-advertise=eth0:0" \ 59 | mha-demo0 60 | 61 | docker-machine create \ 62 | -d amazonec2 \ 63 | --amazonec2-security-group ${group_name} \ 64 | --engine-opt="cluster-store=consul://$(docker-machine ip mha-consul):8500" \ 65 | --engine-opt="cluster-advertise=eth0:0" \ 66 | mha-demo1 67 | -------------------------------------------------------------------------------- /swarm-aws.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | #### Set Up Environment 6 | 7 | if [ -z $AWS_ACCESS_KEY_ID]; then 8 | echo "Please supply your AWS_ACCESS_KEY_ID" 9 | exit 1 10 | fi 11 | if [ -z $AWS_SECRET_ACCESS_KEY]; then 12 | echo "Please supply your AWS_ACCESS_KEY_ID" 13 | exit 1 14 | fi 15 | 16 | group_name="docker-networking" 17 | my_ip="$(wget -q -O- http://icanhazip.com)" 18 | # Get the AMI for your region from this list: https://wiki.debian.org/Cloud/AmazonEC2Image/Jessie 19 | # Paravirtual only - HVM AMI's and Docker Machine don't seem to be working well together 20 | export AWS_AMI="ami-971a65e0" 21 | export AWS_DEFAULT_REGION="eu-west-1" 22 | # This is my default VPC, yours will be different 23 | export AWS_VPC_ID="vpc-69c9a10c" 24 | export AWS_INSTANCE_TYPE="t1.micro" 25 | export AWS_SSH_USER="admin" 26 | 27 | 28 | #### Set up Security Group in AWS 29 | 30 | aws ec2 create-security-group --group-name ${group_name} --description "A Security Group for Docker Networking" 31 | # Permit SSH, required for Docker Machine 32 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 22 --cidr ${my_ip}/32 33 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 2376 --cidr ${my_ip}/32 34 | # Permit Serf ports for discovery 35 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 7946 --cidr 0.0.0.0/0 36 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 7946 --cidr 0.0.0.0/0 37 | # Permit Consul HTTP API 38 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol tcp --port 8500 --cidr 0.0.0.0/0 39 | # Permit VXLAN 40 | aws ec2 authorize-security-group-ingress --group-name ${group_name} --protocol udp --port 4789 --cidr 0.0.0.0/0 41 | 42 | 43 | #### Docker Machine Setup 44 | 45 | docker-machine -D create \ 46 | -d amazonec2 \ 47 | --amazonec2-security-group ${group_name} \ 48 | swa-consul 49 | 50 | docker $(docker-machine config swa-consul) run -d \ 51 | -p "8500:8500" \ 52 | -h "consul" \ 53 | progrium/consul -server -bootstrap 54 | 55 | docker-machine create \ 56 | -d amazonec2 \ 57 | --amazonec2-security-group ${group_name} \ 58 | --swarm \ 59 | --swarm-master \ 60 | --swarm-discovery consul://$(docker-machine ip swa-consul):8500 \ 61 | --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" \ 62 | --engine-opt="cluster-advertise=eth0:0" \ 63 | swa-master 64 | 65 | docker-machine create \ 66 | -d amazonec2 \ 67 | --amazonec2-security-group ${group_name} \ 68 | --swarm \ 69 | --swarm-discovery consul://$(docker-machine ip swa-consul):8500 \ 70 | --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" \ 71 | --engine-opt="cluster-advertise=eth0:0" \ 72 | swa-slave1 73 | --------------------------------------------------------------------------------