Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect docker containers in separate deployments on the same host machine using docker-compose?

I'm having hard time figuring out how to interconnect containers which belong to different docker-compose projects running on the same host.

Let's say, I'm having a set of containers in Deployment A:

root@debussy:~# docker ps | awk '{print $2}' | grep "cl"
cl-worker:latest
cl-nginx:latest
cl-app:latest
cl-rabbitmq:latest
cl-memcached:latest
cl-db:latest

All these containers where launched from a separate configuration file deployment-a.yml. Now, we also have a different Deployment B, with its own `deployment-b.yml:

root@debussy:~# docker ps | awk '{print $2}' | grep "stockagents"
stockagents-app:latest

Is it possible to access Database(cl-db container) from stockagents-app by some specific configuration in deployment-b.yml and/or deployment-a.yml ?

NOTE: I know how to do it using pure docker command and linking containers via --link, but is there a method to achieve the same behaviour using only docker-compose and its configuration files ?

like image 688
Andrew Druchenko Avatar asked Oct 31 '22 06:10

Andrew Druchenko


1 Answers

It seems that recent versions of docker-compose (1.5.2 at least) have support for "external_links" option in docker-compose.yml file which allows to specify containers started outside of the current configuration.

This is exactly the feature I was looking for when trying to share common services (MySQL for example) between containers in separate deployments.

like image 149
Andrew Druchenko Avatar answered Nov 15 '22 05:11

Andrew Druchenko