Docker Networking Tutorial : Connect Containers Across Hosts Using Weave

Weave connects containers across hosts by creating a virtual network. It also has a DNS service which helps in automatic discovery. In this post, we looked into Docker ambassador pattern to connect containers across hosts. In this Docker Networking tutorial, you will learn how  to install and configure weave for connecting containers across hosts.

Installing and Configuring Weave

Follow the steps given below to install and configure Docker weave on both Docker hosts.

Note: TCP/UDP port 6783 should be open for weave to communicate. So make sure that in you firewall rules you have allowed TCP, UDP communication on port 6783 for both.

1. Run the following command as root to download all the necessary files for weave.

2. Execute the following command on two hosts to change the mode of the weave folder.

On Host 1:

Follow the steps given below on host 1.

1. Launch the weave container using the following command.

The above container will launch a weave container which will act as a router.

2. Verify weave installation using the following command.

The output looks like below.

On Host2:

Follow the instructions below for setting up host2.

READ  Docker Tutorial : Getting Started With Docker Swarm

1. Launch weave by passing host1 IP address or hostname (if reachable) as an argument as shown below.

2. Verify the weave installation using the following command.

3. Now we have our two hosts with weave network set up. Let’s launch one container on both hosts using weave and check if there is a connectivity between two containers.

On host 1:

Launch an Ubuntu container on host1 using the weave run the command with 10.2.1.1 IP address as shown below. We will save the container id in a variable.

On host 2:

Launch another container on host 2 with 10.2.1.2 IP address as shown below.

To test the connectivity, on host1, attach to the running container using the following command. $C holds the value of container id.

Ping the container on host2(10.2.1.2) from the attached container. If the ping is successful, you weave network has been successfully configured. You can test the connection from host2 in the same manner we did from host1.

 

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.