Skip to content

Instantly share code, notes, and snippets.

@jgwerner
Last active May 25, 2016 15:25
Show Gist options
  • Save jgwerner/02b3798a98a710ed364ed10e8663ce31 to your computer and use it in GitHub Desktop.
Save jgwerner/02b3798a98a710ed364ed10e8663ce31 to your computer and use it in GitHub Desktop.

Overlay Network on local machine with VirtualBox

Set up K/V server

set up k/v store with virtualbox

docker-machine create -d virtualbox mh-keystore

switch docker to k/v machine context

eval "$(docker-machine env mh-keystore)"

start docker consul in bootstrap mode

docker run -d
-p "8500:8500"
-h "consul"
progrium/consul -server -bootstrap

Set up swarm cluster

set up new virtualbox as swarm master

docker-machine create
-d virtualbox
--swarm --swarm-master
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500"
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500"
--engine-opt="cluster-advertise=eth1:2376"
mhs-demo0

set up another virtualbox and add it to swarm cluster

docker-machine create -d virtualbox
--swarm
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500"
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500"
--engine-opt="cluster-advertise=eth1:2376"
mhs-demo1

list machines to confirm they are up and running

docker-machine ls

If number of containers are not correct, make sure the consul server is running.

Create overlay network

set up env to swarm master

eval $(docker-machine env --swarm mhs-demo0)

### create overlay network. docker network create --driver overlay --subnet=10.0.9.0/24 my-net

make sure network is running

docker network ls

Run test app

### switch context back to swarm master eval $(docker-machine env --swarm mhs-demo0)

start an nginx web server

docker run -itd --name=web --net=my-net --env="constraint:node==mhs-demo0" nginx

switch context to swarm agent

eval $(docker-machine env --swarm mhs-demo1)

start a busy box client

docker run -it --rm --net=my-net --env="constraint:node==mhs-demo1" busybox wget -O- http://web

This should display Welcome to nginx! HTML

Check external connectivity

External connectivity is provided by the docker_gwbridge network

switch context to swarm agent

eval $(docker-machine env mhs-demo1)

check network

docker network ls

switch context to swarm master

eval $(docker-machine env mhs-demo0)

check network

docker network ls

The eth0 interface represents the container interface that is connected to the my-net overlay network. While the eth1 interface represents the container interface that is connected to the docker_gwbridge network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment