How to Connect Two Containers From Different docker-compose Files

Working with Docker containers allows developers to create encapsulated applications that are independent of the host machine and contain all the necessary libraries and dependencies. In practice, docker-compose is often used to configure and manage containers. When several containers are built in a docker-compose file, they are automatically connected to a common network (which is created by default) and can communicate with each other. 

In most cases, however, each project will have its own docker-compose file. In such configurations, the containers from one docker-compose will not be able to connect to those from the other unless we have previously created and configured a shared network. In such cases, it is necessary to use a docker networking in compose. In this article, we’ll take a look at a sample method/example, how to set up networks in different docker-compose files, so that individual projects and the containers/services in them can be connected in a single network when running on a local machine.