WeaveNetwork Plugin

Weave are one of the original Docker plugins, in-fact they were involved in the round table discussions around Dockers plugin functionality, and Weave was included in the original plugin announcement mentioned at the start of this chapter.

Weave describe their network plugin as:

Quickly, easily, and securely network and cluster containers across any environment (on premises, in the cloud, or hybrid) with zero code or configuration.

Anyone who worked with software defined networks will know that this is quite a bold claim, especially a Weave is creating a mesh network.For a full explanation of what that means, I would recommend reading through Weaves own overview which can be found at https://www.weave.works/docs/net/latest/how-it-works/.

Rather than going into any more detail. let's roll our sleeves up and perform an installation. To start with, let's bring up two independent Docker hosts DigitalOcean using Docker Machine.

To make it interesting, we will launch one host in New York Cityand the other in London. As these are going to be acting as individual hosts there is no need to configure Docker Swarm – which is what you would typically need to for multi-host networking with Docker.

To launch the Docker host in New York City run:

docker-machine create 
    --driver digitalocean 
    --digitalocean-access-token 57e4aeaff8d7d1a8a8e46132969c2149117081536d50741191c79d8bc083ae73 
    --digitalocean-region nyc1
   
 weave-nyc

And then for the Docker host in London run:

docker-machine create 
    --driver digitalocean 
    --digitalocean-access-token 57e4aeaff8d7d1a8a8e46132969c2149117081536d50741191c79d8bc083ae73 
    --digitalocean-region lon1 
    weave-lon

Now that we have our two Digital Ocean hosts we need to get Weave up and running.At the time of writing, Weave has not completed the transition to Dockers native plugin architecture and it is due very soon, so we will be using a control script to configure Weave.

First, we need to download the control scripton our NYC Docker host:

docker-machine ssh weave-nyc 'curl -L git.io/weave -o /usr/local/bin/weave; chmoda+x /usr/local/bin/weave'

Once downloaded we can launch Weave using the following command:

docker-machine ssh weave-nyc weave launch --password 3UnFh4jhahFC

This will download and launch several containers on the Docker host, once downloaded the Weave will be configured and the password set meaning that if you want to add a host to network you will need to provide a valid password.

If you do not define a password then anyone will be able to connect to your Weave network, which is fine if you know that your host machines are running on an isolated closed network, however as we are sending traffic over the public internet we have set a password.

You can check the containers by running:

docker $(docker-machine config weave-nyc) container ps

Now that we have the three containers we need launched, it is time to install Weave on our London Docker host and then connect it to our NYC Docker host. To do the installation run the following commands:

docker-machine ssh weave-lon 'curl -L git.io/weave -o /usr/local/bin/weave; chmoda+x /usr/local/bin/weave'
docker-machine ssh weave-lon weave launch --password 3UnFh4jhahFC

Once the three containers have launched, simply run the following command to connect to our NYC Docker host:

docker-machine ssh weave-lon weave connect "$(docker-machine ip weave-nyc)"

Once our second host has been configured you can check the status of the Weave mesh network by running:

docker-machine ssh weave-nyc weave status
WeaveNetwork Plugin

As you can see from the preceding terminal above, we have five services running, and other than providing a password, we didn't have to configure any of them.

As I am running a Mac OS machine, I am also going to install Weave locally, the same instructions will also work on a Linux machine.

The following commands will install the Weave control script which will be used to launch the containers within your Docker for Mac installation and connect to our Weave mesh network:

sudo curl -L git.io/weave -o /usr/local/bin/weave; sudochmoda+x /usr/loca
l/bin/weave
weave launch --password 3 UnFh4jhahFC
weave connect "$(docker-machine ip weave-nyc)"

Once installed and connected, running weave status locally should show you that there are now 3 peers with 6 established connections:

WeaveNetwork Plugin

So now we have three Docker hosts:

  • One in NYC hosted by Digital Ocean
  • One in London hosted by Digital Ocean
  • Our local Docker host running on Docker for Mac (or Linux)

All with a network called weave using the weavemesh driver. You can confirm this by running:

docker network ls
docker $(docker-machine config weave-nyc) network ls
docker $(docker-machine config weave-lon) network ls

You should see something similar to the following terminal output:

WeaveNetwork Plugin

Now we are ready to start launching containers into our Weave network and demonstrate that they can communicate with each other.

Note

Netcat is a service which allows you to be read and write to a network using TCP or UDP.

Let's start by launching a container in NYC running Netcat(nc). Each time a request is sent to port 4242 nc will answer with Hello from NYC!!!:

docker $(docker-machine config weave-nyc) container run -itd 
  --name=nyc 
  --net=weave 
  --hostname="nyc.weave.local" 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine nc -p 4242-ll -e echo 'Hello from NYC!!!'

As you can see from the Docker command, we are passing quite a few different options, we are telling the container which network to use, as well configuring the DNS resolver within the container and setting a hostname of nyc.weav e.local.

WeaveNetwork Plugin

Now that we have our NYC container up and running, the first thing to do is to check if we can ping from our London Docker host, to do this run the following:

docker $(docker-machine config weave-lon) container run -it --rm 
  --name=ping 
  --net=weave 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine sh -c 'ping -c3 nyc.weave.local'

This will send three pings to nyc.weave.local, all of which should be answered:

WeaveNetwork Plugin

Now that have confirmed that we can Ping the NYC container, we need to connect to port 4242 and check if we get the response we expect:

docker $(docker-machine config weave-lon) container run -it --rm 
  --name=conect 
  --net=weave 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine sh -c 'echo "Where are you?" | ncnyc.weave.local 4242'

You should receive the message Hello from NYC!!!:

WeaveNetwork Plugin

Now let's launch a container on our local Docker host using the following command:

docker container run -itd 
  --name=mac 
  --net=weave 
  --hostname="mac.weave.local" 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine nc -p 4242 -ll -e echo 'Hello from Docker for Mac!!!'
WeaveNetwork Plugin

As before, we will do a simple ping test to our local container:

docker $(docker-machine config weave-nyc) container run -it --rm 
  --name=ping 
  --net=weave 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine sh -c 'ping -c3 mac.weave.local'

As expected, we receive a response:

WeaveNetwork Plugin

It's a little slow to start with, but it eventually gets better. Now that we know we can ping our local container lets connect to port 4242 and check the response. First, from our NYC Docker host:

docker $(docker-machine config weave-nyc) container run -it --rm 
  --name=conect 
  --net=weave 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine sh -c 'echo "Where are you?" | ncmac.weave.local 4242'

Then from our London Docker host:

docker $(docker-machine config weave-lon) container run -it --rm 
  --name=conect 
  --net=weave 
  --dns="172.17.0.1" 
  --dns-search="weave.local" 
  alpine sh -c 'echo "Where are you?" | ncmac.weave.local 4242'

As you can see from the following terminal output we got the answer we expected to receive:

WeaveNetwork Plugin

To tidy up your local Docker host run the following commands:

docker container stop mac
docker container rm mac
weave stop
sudorm -f /usr/local/bin/weave

And then to terminate our two Digital Ocean hosts run:

docker-machine stop weave-lon weave-nyc
docker-machine rm weave-lon weave-nyc

While these tests haven't been as visually interesting as the walkthrough of the REX-Ray Volume plugin, as you have seen, Weave is an incredibly powerful software-defined network, which is very easy to configure.

Speaking fromexperience, this is a difficult combination to pull off, as most SDN solutions are incredibly complex to install, configure, and maintain.

We have only touched on what is possible with Weave. For a full feature list, along with instructions on some most of the advanced use cases, refer to http://docs.weave.works/weave/latest_release/features.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset