Docker Multi-Host Networking Tutorial – Using Consul

Now docker has production ready multi-host networking capabilities and it has commands to manage networks from the command line. This guide walks you through the basic docker multi-host networking using docker machine and consul service discovery tool.

[alert style=”e.g. white, grey, red, yellow, green”] There is only one prerequisite for this tutorial. You just need the latest docker toolbox installed on your system.[/alert]

Docker Multi-Host Networking

In this setup, we will create three docker hosts on virtual box using docker machine. One host runs consul and other  two hosts share the network information using consul service discovery container on the first host. You can learn more about consul from here.

[alert style=”e.g. white, grey, red, yellow, green”] To know more about networking basics, refer this official docker documentation[/alert]

Follow the steps given below to set up multi-host networking.

1. Create a docker machine named “host1-consul”

2. Launch a consul container on the host1-consul host using the following docker run command.

3. You can verify the running container status using the following command.

4. Now, launch the second docker machine host with parameters to register it with consul running on the host1-consul host.

5. Launch the third docker machine.

READ  How To Install and Configure GUI for Amazon EC2 RHEL 7 Instance

Now the two hosts have the default networks which can be used only for single host communication.

6. To have a multi-host network we need to create an overlay network on host2 using the “docker network” command as shown below.

7. Now, if you check the networks on host3, you will be able to see the overlay network we created on host2. It is because our two hosts are registered with consul and the network information is shared among all the hosts which are registered with it.

Now, if you launch containers in the differnt host, you will be able to connect them using the container name. Let test it by launching a Nginx container on host2 and test the connection by downloading the default Nginx page from host3 using a busybox container.

8. Launch a Nginx container on host2 by specifying the network “myapp” we have created.

9. Verify the running container.

10. Now, launch a busybox container on host3 with parameters to download the homepage of nginx running on host2.

READ  Docker Machine Tutorial : Getting Started Guide

If the above command returns an HTML output, it means the containers are able to connect to hosts using the overlay network you have created.

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.