Concerning Containers' Connections: on Docker Networking

Figure 4. Using Weave, containers in local and remote networks connect to each other transparently; access is simplified with Weave DNS.

Now, let's get your mini-system to run. I'm going to cheat a little, and instead of a remote server, I'll use a virtual machine for this example. My main box (at runs OpenSUSE 13.2, while the virtual machine (at runs Linux Mint 17, just for variety. Despite the different distributions, Docker containers will work just the same, which shows its true portability (Listing 8).

Listing 8. Getting the Weave network to run on two servers.

> # At (OpenSUSE 13.2 server)
> su -
$ weave launch
$ weave launch-dns
$ C=$(weave run --with-dns -it -d -e 
 ↪MYSQL_ROOT_PASSWORD=ljdocker -h MYDB.weave.local --name MYDB worlddb)
$ # You can now enter MYDB with "docker exec -it $C bash"

> # At (Linux Mint virtual machine)
> su -
$ weave launch
$ weave launch-dns
$ weave connect
$ D=$(weave run --with-dns -it -d -p 80:80 -h 
 ↪MYWEB.weave.local --name MYWEB worldweb)

The resulting configuration is shown in Figure 5. There are two hosts, on and Although it's not shown, both have port 6783 open for Weave to work. In the first host, you'll find the MYDB MySQL container (at with port 3306 open, but just on that subnet) and a WeaveDNS server at In the second host, you'll find the MYWEB Apache+PHP container (at with port 80 open, exported to the server) and a WeaveDNS server at From the outside, only port 80 of the MYWEB container is accessible.

Figure 5. The final Docker container-based system, running on separate systems, connected by Weave.

Because port 80 on the server is directly connected to port 80 on the MYWEB server, you can access and get the Web page you saw earlier (in Figure 2). Now you have a multi-host Weave network, with DNS services and remote Docker containers running as if they resided at the same host—success!


Now you know how to develop a multi-container system (okay, it's not very large, but still), and you've learned some details on the internals of Docker (and Weave) networking. Docker is still maturing, and surely even better tools will appear to simplify configuration, distribution and deployment of larger and more complex applications. The current availability of networking solutions for containers shows you already can begin to invest in these technologies, although be sure to keep up with new developments to simplify your job even further.


Get Docker itself from The actual code is at

For more detailed documentation on Docker network configuration, see

The docker-dns site is at, and its source code is at

The official MySQL Docker image is at If you prefer, there also are official repositories for MariaDB ( Getting it to work shouldn't be a stretch.

The Apache+PHP official Docker image is at

Weave is at, and the code itself is on GitHub at For more detailed information on its features, go to

WeaveDNS is on GitHub at

For more on articles on Docker in Linux Journal, read the following:

The geographical data I used for the example in this article comes from GeoNames In particular, I used the countries table ( and the cities (with more than 1,000 inhabitants) table (, but there are larger and smaller sets.