Docker Networking

Connecting containers is very important for most of the applications out there. A classic web application consists of at least a web server, an application server and a database server. The web server needs to talk to the application server and the application server would need to talk to database server. A legacy, but popular way to do so is via passing --link flag to docker run command.

$ sudo docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql
$ sudo docker run --link mysql -i -t centos /bin/bash

Currently, Docker has a very elaborated network suite to cater to a wide variety of use-cases. By default it comes with three network pre-configured:

Please take moment to run a container in all these network and run ifconfig or ip addr.

$ sudo docker run --net=<type_of_the_network> -i -t centos /bin/bash

Docker does not limit us to these three networks only. We can create additional networks as and when required. This helps in maintaining isolation between networks and improves security. Docker lets us create two kinds of user-defined networks: