I was recently trying to containerize an application that uses three services. When starting their containers separately with docker run, I also need to put them in the same network otherwise they can’t communicate. But I just wrote a docker-compose.yaml file to run them at the same time and they can communicate with each other even without specifying their network interface. Why is that?
>Solution :
docker-compose create a stack with a default network.
From docker-compose documentation :
"By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by the service’s name."
If you want to customize, you need to use network directive in your docker-compose.yml file.
Hope this help