Docker supports the concept of virtual networks. Docker Compose uses them to provide network isolation between applications. By default, every application started with Docker Compose has its own virtual network named after the application's namespace. That means, if you start two different applications with docker-compose
, they will not be able to see each other.
Within an application's namespace, the network created by docker-compose
provides DNS service discovery. In the case of the example multi-container application, there were DNS entries created for the web and database services called web
and db
, respectively. In the configuration for the web application (MyApp/config.yml.in
), the database connection is configured to connect to a host named db
. Docker does the rest by making sure that the db
hostname points to the db
service.