Sobes.tech
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:

  1. Create a shared user-defined network manually:
docker network create my_shared_network
  1. In each docker-compose file, specify the use of this network:
networks:
  default:
    external:
      name: my_shared_network
  1. Run both docker-compose files (for example, docker-compose -f docker-compose1.yml up -d and docker-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.