Docker Community Forums

Share and learn in the Docker community.

How to link two docker containers which are spawned with two different docker-compose.yml


(Bala529) #1

I have two containers. Each one is spawned in two different docker-compose. How can I link between these containers.
Example: in a single docker-compose`

 input:
  build: InputBuffer
  links:    
    - queue
    - output
  ports:
    - "30005:30005/udp"`

But in the links part, I want to link to another container which is spawned by another docker-compose.yml in the same host. Here in the example I have linked containers of the same docker-compose.yml.


(Jeff Anderson) #2

Hello! sorry for the late reply, but here goes anyway:

Compose has an “external links” feature. It allows you to link to a container that already exists (whether it was created by another compose file or not): https://docs.docker.com/compose/yml/#external-links

If would argue, however, that linking containers together would make them part of the same logical application. Generally, I like having one compose file for one application.


(Kevincantwell) #3

Hi @programmerq,
I’m just ramping up with docker and docker compose and I’d also like to use a single compose file for the entire applicaiton. Problem is, we have dozens of repos that each represent one or more containers. Many of which have dependencies on shared resources like postgres. Any organizational tips?

Thanks in advance!


(Dvohra) #4

Any organizational tips?
The development team should use the same compose file and not multiple files that need to be linked.