I have two docker compose files, for example backend and monitoring. I need to create communication between them. It is possible using same network, and docs telling me to create network in one file and then use
external: true
in another.
But I want possibility to run only backend or only monitoring. And of course I want them to communicate if they both are running.
I can create the network with
docker network create some_network
and then run one or another, or both of them but are there some better ways?
2
Answers
You should:
Edit:
Due your comment, I propose you the following scenario:
docker-compose build -f network.yaml -f container-a.yaml -f container-b.yaml .
.That’s all!
A network is the best way to restrict its communication to the containers itself. You could also open up the ports but this solution is inferior in terms of security to the previous one.