Senior
How to connect services from two different docker-compose files?
sobes.tech AI
Answer from AI
To connect services from two different docker-compose files, you need to ensure they are in the same Docker network. You can:
- Create a shared user-defined network manually:
docker network create my_shared_network
- In each docker-compose file, specify the use of this network:
networks:
default:
external:
name: my_shared_network
- Run both docker-compose files (for example,
docker-compose -f docker-compose1.yml up -danddocker-compose -f docker-compose2.yml up -d).
After that, services can communicate with each other by container or service names, as they are in the same network.
It is important that service names are unique to avoid conflicts. You can also use the depends_on option to manage the startup order if necessary.